我運行下面的代碼(的一部分)的SQL數據添加到一個數據庫需要連接到PHPmyadmin
DB是.ExecuteNonQuery()來在vb.net
Private Sub sreg_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SqlConnection.ConnectionString = ServerString
Try
If SqlConnection.State = ConnectionState.Closed Then
SqlConnection.Open()
MsgBox("Successfully connected to MySQL DB")
Else
SqlConnection.Close()
MsgBox("Connection is Closed")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub SaveNames(ByRef SQLStatment As String)
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = SQLStatment
.CommandType = CommandType.Text
.Connection = SqlConnection
.ExecuteNonQuery()
End With
SqlConnection.Close()
MsgBox("Succesfully Added!")
SqlConnection.Dispose()
End Sub
然而.ExecuteNonQuery()
是給了我巨大的在錯誤和問題方面令人頭痛。它上傳數據,但它只能做一次(一次上傳),它會返回一個錯誤。
當我刪除了.ExecuteNonQuery()
沒有數據被上傳?所以我想這是必要的。
這裏是代碼即時上傳(的一部分)
sql = "INSERT INTO students(student_id, title, initial, surname,
street, city, pcode, country) VALUES ('" & strStudent & "', '"
& vtital & "', '" & vinital & "', '" & vsurname & "', '" & vstreet
& "', '" & vcity & "', '" & vpcode & "', '" & vcountry & "')"
SaveNames(sql)
希望我的問題是有道理的,我也可以得到跨
在學生表是student_id數據的主鍵自動增加?什麼是你得到的錯誤信息? – Milen
'它返回一個錯誤'什麼錯誤? – walther
@MilenPavlov是student_id數據是主鍵不自動增加 – Marilee