【发布时间】:2011-12-16 04:59:25
【问题描述】:
这是我在 VB.NET 中的代码。
我的 try catch 说指令 INSERT INTO 中存在语法错误。我不知道我的 INSERT 发生了什么。我搜索了一个多小时的错误...我不是 VB.NET 方面的专家,我在 C# 方面做得更好,但无论如何我都需要在 VB 中这样做...
谢谢你帮助我!!
Sub InsertRecord()
Dim conClasf As OleDbConnection
Dim cmdClasf As New OleDbCommand
Dim strClasf As String
Dim strSQL As String
Dim intRowsAff As Integer
lblErrMsg.Text = ""
lblRecsAff.Text = ""
strClasf = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
server.mappath("BecsEtMuseaux.mdb") & ";"
conClasf = New OleDbConnection(strClasf)
conClasf.Open
Randomize
strSQL = "INSERT INTO client (" & _
"UserName, " & _
"Prenom, " & _
"Nom, " & _
"password, " & _
"mail, " & _
"Addresse, " & _
"Ville, " & _
"PostalCode, " & _
"Province, " & _
"Pays, " & _
"AnimalGenre, " & _
"NomAnimal, " & _
"Race, " & _
") VALUES ('" & _
Replace(txtUserName.Text, "'", "''") & _
"', '" & _
Replace(txtPrénom.Text, "'", "''") & _
"', '" & _
Replace(txtNom.Text, "'", "''") & _
"', '" & _
Replace(txtPass.Text, "'", "''") & _
"', '" & _
Replace(txtMail.Text, "'", "''") & _
"', " & _
Replace(txtAdresse.Text, "'", "''") & _
"', " & _
Replace(txtVille.Text, "'", "''") & _
"', " & _
Replace(txtPostal.Text, "'", "''") & _
"', " & _
Replace(txtProvince.Text, "'", "''") & _
"', " & _
Replace(txtPays.Text, "'", "''") & _
"', " & _
Replace(rblAnimal.Text, "'", "''") & _
"', " & _
Replace(txtAnimal.Text, "'", "''") & _
"', " & _
Replace(txtRace.Text, "'", "''")
cmdClasf = New OleDbCommand(strSQL, conClasf)
Try
intRowsAff = cmdClasf.ExecuteNonQuery()
Catch ex As Exception
lblErrMsg.Text = ex.Message
End Try
lblRecsAff.Text = intRowsAff & " record(s) inserted"
conClasf.Close
End Sub
【问题讨论】: