来自 OleDbCommandBuilder 的 InsertCommand 中的语法错误
Syntax error in InsertCommand from OleDbCommandBuilder
我正在尝试使用此代码将新订单添加到我的数据库中。我以前使用过相同的代码,但现在不起作用。你能帮忙吗?
我正在使用 Microsoft Visual Basic 2008 Express Edition 和 Microsoft Access。
我有四张桌子。
CurrentRowNo = 0
' Purpose: Add new Account record and assign its default values
' Clear the Account table in the DataSet ready for a new record to be added
SandRDataSet.Tables("Stock").Clear()
'Add a new record to the studnet table
Dim driveletter As String = Application.StartupPath.Substring(0, 1)
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & driveletter & ":\raheem\Computing\Database\SandR.accdb")
cn.Open()
Dim daStock As New OleDbDataAdapter("SELECT * FROM Stock;", cn)
Dim sqlcmdbldStudent As New OleDb.OleDbCommandBuilder(daStock)
'Fill the database
daStock.Fill(SandRDataSet, "Stock")
Dim test As DataRow = SandRDataSet.Tables("Stock").NewRow
test("Product/Service number") = txtProductNo.Text
test("Product/ Service name") = txtProductName.Text
test("minimum level") = txtMin.Text
test("maximum level") = txtMax.Text
test("Quantity") = txtQuantity.Text
test("Price") = txtPrice.Text
SandRDataSet.Tables("Stock").Rows.Add(test)
sqlcmdbldStudent.GetInsertCommand()
daStock.InsertCommand = sqlcmdbldStudent.GetInsertCommand
daStock.Update(SandRDataSet.Stock)
DisplayAccount()
cn.Dispose()
cn.Close()
如果您的 table 中确实有该列名称(Space 和正斜杠),那么我建议您将 QuotePrefix 和 QuoteSuffix 设置为您的 OleDbCommandBuilder
Dim sqlcmdbldStudent As New OleDb.OleDbCommandBuilder(daStock)
sqlcmdbldStudent.QuotePrefix = "["
sqlcmdbldStudent.QuoteSuffix = "]"
这将强制将命令生成器创建的字段名称括在方括号中并由数据库引擎正确解释
我正在尝试使用此代码将新订单添加到我的数据库中。我以前使用过相同的代码,但现在不起作用。你能帮忙吗?
我正在使用 Microsoft Visual Basic 2008 Express Edition 和 Microsoft Access。
我有四张桌子。
CurrentRowNo = 0
' Purpose: Add new Account record and assign its default values
' Clear the Account table in the DataSet ready for a new record to be added
SandRDataSet.Tables("Stock").Clear()
'Add a new record to the studnet table
Dim driveletter As String = Application.StartupPath.Substring(0, 1)
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & driveletter & ":\raheem\Computing\Database\SandR.accdb")
cn.Open()
Dim daStock As New OleDbDataAdapter("SELECT * FROM Stock;", cn)
Dim sqlcmdbldStudent As New OleDb.OleDbCommandBuilder(daStock)
'Fill the database
daStock.Fill(SandRDataSet, "Stock")
Dim test As DataRow = SandRDataSet.Tables("Stock").NewRow
test("Product/Service number") = txtProductNo.Text
test("Product/ Service name") = txtProductName.Text
test("minimum level") = txtMin.Text
test("maximum level") = txtMax.Text
test("Quantity") = txtQuantity.Text
test("Price") = txtPrice.Text
SandRDataSet.Tables("Stock").Rows.Add(test)
sqlcmdbldStudent.GetInsertCommand()
daStock.InsertCommand = sqlcmdbldStudent.GetInsertCommand
daStock.Update(SandRDataSet.Stock)
DisplayAccount()
cn.Dispose()
cn.Close()
如果您的 table 中确实有该列名称(Space 和正斜杠),那么我建议您将 QuotePrefix 和 QuoteSuffix 设置为您的 OleDbCommandBuilder
Dim sqlcmdbldStudent As New OleDb.OleDbCommandBuilder(daStock)
sqlcmdbldStudent.QuotePrefix = "["
sqlcmdbldStudent.QuoteSuffix = "]"
这将强制将命令生成器创建的字段名称括在方括号中并由数据库引擎正确解释