【发布时间】:2015-01-06 13:01:26
【问题描述】:
我正在尝试使用此代码将新订单添加到我的数据库中。我以前使用过相同的代码,但现在不起作用。你能帮忙吗?
我正在使用 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()
【问题讨论】:
-
您能否提供有关错误的更多详细信息
-
欢迎来到 Stack Overflow!请花点时间仔细地查看:How to Ask