filmov
tv
MySQL Connection to Visual Studio .Net

Показать описание
The tutorial shows how to connect MySQL to VB.Net. Below is the major code that i used.
Dim myconn As New MySqlConnection(-server=localhost;user id=root; password=locked; database=user-) 'this is supposed to be a Public declaration as in the program
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cmd As New MySqlCommand
If TextBox1.Text = -- Or TextBox2.Text = -- Or TextBox3.Text = -- Or TextBox4.Text = -- Or TextBox5.Text = -- Then
MsgBox(-Provide all details!-)
Else
Try
myconn.Open()
cmd.Connection = myconn
cmd.CommandText = -insert into person (firstname,surname,username,password) values ('- & TextBox1.Text & -','- & TextBox2.Text & -','- & TextBox3.Text & -','- & TextBox4.Text & -')-
cmd.ExecuteNonQuery()
MsgBox(-SAVED-)
TextBox1.Text = --
TextBox2.Text = --
TextBox3.Text = --
TextBox4.Text = --
TextBox5.Text = --
myconn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Dim myconn As New MySqlConnection(-server=localhost;user id=root; password=locked; database=user-) 'this is supposed to be a Public declaration as in the program
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cmd As New MySqlCommand
If TextBox1.Text = -- Or TextBox2.Text = -- Or TextBox3.Text = -- Or TextBox4.Text = -- Or TextBox5.Text = -- Then
MsgBox(-Provide all details!-)
Else
Try
myconn.Open()
cmd.Connection = myconn
cmd.CommandText = -insert into person (firstname,surname,username,password) values ('- & TextBox1.Text & -','- & TextBox2.Text & -','- & TextBox3.Text & -','- & TextBox4.Text & -')-
cmd.ExecuteNonQuery()
MsgBox(-SAVED-)
TextBox1.Text = --
TextBox2.Text = --
TextBox3.Text = --
TextBox4.Text = --
TextBox5.Text = --
myconn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Комментарии