这是我试图将数据插入数据库的一段代码。我没有收到任何语法错误,但它没有提交数据。
Sub submit(ByVal sender As Object, ByVal e As EventArgs)
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim strConnString, strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("Mydatabase.mdb") & ""
strSQL = "INSERT INTO tblRecord (CNIC,Names,City,Address,Number) " & " VALUES " & " ('" & cnic.Text & "','" & name.Text & "','" & city.Text & "','" & postal.Text & "','" & phone.Text & "')"
objConn.ConnectionString = strConnString
objConn.Open()
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
Label1.Text = "Record Inserted Sucessfully."
Label1.Visible = True
Catch ex As Exception
Label1.Visible = True
Label1.Text = "Record Cannot Insert" & ex.ToString()
End Try
objConn.Close()
End Sub
这是我得到的例外:
System.Data.OleDb.OleDbException:INSERT INTO 语句中的语法错误。
在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
在 System.Data。 OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at ASP.registration_aspx.submit(Object sender , EventArgs e) 在 C:\Documents and Settings\Maira Alvi\My Documents\Visual Studio 2005\WebSites\WebSite3\Registration.aspx:line 32