當我嘗試在這三個字段中插入數據時,在INSERT INTO語句中出現錯誤說錯誤。 但只保存在第一個字段sname它被添加,但當添加其他兩個得到這個錯誤 我得到一個異常在INSERT INTO語句檢查 以下任何建議?在INSERT INTO的vb.net代碼錯誤
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
Me.con = New OleDb.OleDbConnection()
con.ConnectionString = dbprovider
con.Open()
Dim sqlquery As String = "INSERT INTO admin (sname,username,password)" + "VALUES ('" & txtname.Text & "','" & txtuser.Text & "','" & txtpass.Text & "');"
Dim sqlcommand As New OleDb.OleDbCommand(sqlquery)
With sqlcommand
.CommandText = sqlquery
.Connection = con
.ExecuteNonQuery()
con.Close()
End With
MsgBox("User Registered")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
除了你的問題,你真的應該保護自己免受*** [SQL注入](http://msdn.microsoft.com/en-us/library/ff648339.aspx)*** ... – 2013-04-04 17:59:24
我同意,雖然這不是嚴重的只是kickabout的東西.... – CrashOverride 2013-04-04 18:03:02