我試圖從 c# 轉換為 vb.net,但出現錯誤。有沒有解決方案,我使用 Visual Studio 2010。我發布了完整的代碼
謝謝杰克
'In the insert form:
Public Sub New(ByVal f2 As Form2)
InitializeComponent()
frm2 = f2
End Sub
Public Delegate Sub UpdateDelegate(ByVal sender As Object, ByVal args As UpdateEventArgs)
Public Event UpdateEventHandler As UpdateDelegate
Private frm2 As Form2
Public Class UpdateEventArgs
Inherits EventArgs
Public Property Data() As String
End Class
Protected Sub raiseUpdate()
Dim args As New UpdateEventArgs()
UpdateEventHandlerEvent?.Invoke(Me, args) 'this error Argument not specified for parameter and character cannot be used
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim sqlCon As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\v-baf\OneDrive\MyWork\MyWinFrm\WinFormApplication20170302\WinFormApplication20170517 \DB\Database1.mdf;Integrated Security=True"
Using conn As New SqlConnection(sqlCon)
conn.Open()
Using cmd As SqlCommand = conn.CreateCommand()
cmd.CommandText = "insert into Table1(Character, Level, Clan) values('" & textBox2.Text & "','" & textBox3.Text & "','" & textBox4.Text & "')"
cmd.ExecuteNonQuery()
End Using
End Using
raiseUpdate()
End Sub
uj5u.com熱心網友回復:
I think you'll need to use either:
RaiseEvent UpdateEventHandler(Me, args)
Or:
If UpdateEventHandlerEvent IsNot Nothing Then UpdateEventHandlerEvent.Invoke(Me, args)
(I suspect your ancient VB doesn't understand the ?. syntax the converter has generated)
Your name of your event could do with some improvement; consider calling it something like:
Public Event DataInserted As ...
Also, complete aside, read http://bobby-tables.com as a matter of urgency and never again write an SQL like you have done there; it enables the number one easy way to hack a system that has a database
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/448568.html
