我有這個代碼,但是當我嘗試執行它時,我總是收到一個消息框,說Syntax error in INSERT statement
我不知道最新的錯誤。有人能幫我嗎?我是一個新手在數據庫中插入數據
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("some fields are empty ")
Exit Sub
ElseIf TextBox2.Text <> TextBox3.Text Then
MsgBox("password do not match ")
Exit Sub
Else
ans = MsgBox(" are you want to ADD this user? ", MsgBoxStyle.YesNo,
"confirm ")
If ans = MsgBoxResult.Yes Then
Try
Dim SqlQuery = "INSERT INTO login (user,pass) VALUES _
('" & TextBox1.Text & "','" & TextBox2.Text & "')"
Dim sqlcommand As New OleDbCommand
With sqlcommand
.CommandText = SqlQuery
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("User Succesfully added", MsgBoxStyle.Information)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
Exit Sub
End If
End If
End Sub
連接對象定義在哪裏? –
你是什麼意思?即時通訊一個newbee .. – user3242798
你在哪裏連接對象被定義,並且它是連接打開? –