visual basic插入到一个mysql数据库上的多个表中
您好,我想知道是否可以单击一个按钮将相同的数据发送到一个数据库但多个表。因为在我目前的情况下,我只把数据放在两个数据中的第一个。以下是所述按钮的完整代码:visual basic插入到一个mysql数据库上的多个表中,mysql,visual-studio-express,Mysql,Visual Studio Express,您好,我想知道是否可以单击一个按钮将相同的数据发送到一个数据库但多个表。因为在我目前的情况下,我只把数据放在两个数据中的第一个。以下是所述按钮的完整代码: Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click MsgBox("Meld enige gebreken bij je leraar samen de naam van de computer (deze staa
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MsgBox("Meld enige gebreken bij je leraar samen de naam van de computer (deze staat op de stikker die op het apparaat te vinden is)")
Dim myHost As String = Dns.GetHostName
Dim ipEntry As IPHostEntry = Dns.GetHostEntry(myHost)
Dim ip As String = ""
Dim nee As String
Dim user As String
nee = "nee"
dbconn = New MySqlConnection("Data Source=172.17.80.153;user id=connectinguser;password=123456;database=vbtest;")
Try
dbconn.Open()
Catch ex As Exception
MsgBox("Error in connection, please check Database and connection server.")
End Try
For Each tmpIpAddress As IPAddress In ipEntry.AddressList
If tmpIpAddress.AddressFamily = Sockets.AddressFamily.InterNetwork Then
Dim ipAddress As String = tmpIpAddress.ToString
ip = ipAddress
Exit For
End If
Next
If ip = "" Then
Throw New Exception("No 10. IP found!")
End If
If TypeOf My.User.CurrentPrincipal Is System.Security.Principal.WindowsPrincipal Then
' The application is using Windows authentication.
' The name format is DOMAIN\USERNAME.
Dim parts() As String = Split(My.User.Name, "\")
Dim username As String = parts(1)
Dim uname As String = My.User.Name
uname = uname.Remove(0, 10)
user = uname
End If
sql = "INSERT INTO tbl_nee(Gebruikersnaam,Computernaam,IPAddress, Keuze) VALUES('" & user & "', '" & My.Computer.Name & "', '" & ip & "', '" & nee & "' )"
sql = "INSERT INTO tbl_alles(Gebruikersnaam,Computernaam,IPAddress, Keuze) VALUES('" & user & "', '" & My.Computer.Name & "', '" & ip & "', '" & nee & "' )"
Try
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
Catch ex As Exception
MsgBox("Error in saving to Database. Error is :" & ex.Message)
dbread.Close()
Exit Sub
End Try
Me.Close()
End Sub
它有点乱,但我不是一个好的编码员,所以它只是各种各样的东西,可以让它工作。谢谢,但是我现在怎么才能删除它们呢?仅将dim sql1作为字符串,dim sql2作为字符串?还有更多吗?因为它仍然不适用于我。请在此处粘贴错误代码。我不想看到您遇到了什么样的错误。我得到了关于“;”Dim sql1 As String=”“”的这些错误;对不起,我在声明的末尾加了分号。这是类似C语言的习惯。请删除该分号,然后重试。它应该是有效的。它不起作用。它没有给出错误,但它没有添加到tbl_alles中
Dim sql1 As String = ""
Dim sql2 As String = ""
sql1 = "INSERT INTO tbl_nee(Gebruikersnaam,Computernaam,IPAddress, Keuze) VALUES('" & user & "', '" & My.Computer.Name & "', '" & ip & "', '" & nee & "' )"
sql2 = "INSERT INTO tbl_alles(Gebruikersnaam,Computernaam,IPAddress, Keuze) VALUES('" & user & "', '" & My.Computer.Name & "', '" & ip & "', '" & nee & "' )"
Dim sql = String.Concat(sql1, ";", sql2)
Try
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
Catch ex As Exception
MsgBox("Error in saving to Database. Error is :" & ex.Message)
dbread.Close()
Exit Sub
End Try