Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

vb.net - my output doesn't go to database due to "syntax erron in insert into statement"

 myConnection.ConnectionString = connString
 myConnection.Open()
 Dim str As String
 str = "Insert into connect([jersey],[Fname],[Mname],[Lname]) Values (?,?,?,?)"
 Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
 cmd.Parameters.Add(New OleDbParameter("jersey", CType(TextBox1.Text, String)))
 cmd.Parameters.Add(New OleDbParameter("Fname", CType(TextBox2.Text, String)))
 cmd.Parameters.Add(New OleDbParameter("Mname", CType(TextBox3.Text, String)))
 cmd.Parameters.Add(New OleDbParameter("Lname", CType(TextBox4.Text, String)))
 Try
     cmd.ExecuteNonQuery()
     cmd.Dispose()
     myConnection.Close()
     TextBox1.Clear()
     TextBox2.Clear()
     TextBox3.Clear()
     TextBox4.Clear()
  Catch ex As Exception
     MsgBox(ex.Message)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

CONNECT is a Access database engine reserved word

Put square brackets around and it should work.

Insert into [connect] ([jersey],[Fname],[Mname],[Lname]) Values (?,?,?,?)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...