Dim myAdapter As New MySqlDataAdapter
Dim myCommand As New MySqlCommand
Dim myData As MySqlDataReader
Dim add As String
Dim connect As MySqlConnection
connect = New MySqlConnection()
connect.ConnectionString = "Server=127.0.0.1 ;Userid=root ;Password=123456;Database=login "
Dim usercheck As String = "SELECT username FROM logintest WHERE username = '" + txtuser.Text + "'"
Try
connect.Open()
Catch myerror As MySqlException
MsgBox("Error connecting to database. Check your internet connection.", MsgBoxStyle.Critical)
End Try
myCommand.Connection = connect
myCommand.CommandText = usercheck
myAdapter.SelectCommand = myCommand
myData = myCommand.ExecuteReader
If myData.HasRows = 0 Then
add = "INSERT INTO logintest (username,password) VALUES('" + txtuser.Text + "','" + txtpass.Text + "')"
MsgBox("สมัครเรียบร้อย")
Else
MsgBox(txtuser.Text & " is being register, try again.", MsgBoxStyle.Information)
End If
connect.Close()
Dim newProdID As Int32 = 0
Dim sql As String = _
"INSERT INTO Production.ProductCategory (Name) VALUES (@Name); " _
& "SELECT CAST(scope_identity() AS int);"
Using conn As New SqlConnection(connString)
Dim cmd As New SqlCommand(sql, conn)
cmd.Parameters.Add("@Name", SqlDbType.VarChar)
cmd.Parameters("@Name").Value = newName
Try
conn.Open()
newProdID = Convert.ToInt32(cmd.ExecuteScalar())
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Using