I tried to convert from c# to vb.net but there was an error. Is there a solution and I use visual studio 2010. I post full code
thanks jack
'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
CodePudding user response:
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