Public Class frmOrder
Dim ItemNumber As String
Dim con As New OleDb.OleDbConnection
Dim dbprovider As String
Dim dbsource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim ds1 As New DataSet
Dim da1 As OleDb.OleDbDataAdapter
Dim sql1 As String
Dim ds2 As New DataSet
Dim da2 As OleDb.OleDbDataAdapter
Dim sql2 As String
Dim ds3 As New DataSet
Dim da3 As OleDb.OleDbDataAdapter
Dim sql3 As String
Dim ds4 As New DataSet
Dim da4 As OleDb.OleDbDataAdapter
Dim sql4 As String
Dim lastReceiptNumber As Integer
Dim CustomerID1 As Integer
Private Sub frmOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ItemNumber = frmShop.Label13.Text
CustomerID1 = Convert.ToInt32(frmLogin.Label3.Text)
dbprovider = "PROVIDER = Microsoft.ACE.OLEDB.12.0;"
dbsource = "Data Source = C:\Users\Patrick\Desktop\FinalDatabase.accdb"
con.ConnectionString = dbprovider + dbsource
con.Open()
sql = "SELECT * FROM ITEMS"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Items")
sql1 = "SELECT Address FROM CUSTOMER WHERE CustomerID= " & CustomerID1 & ""
da1 = New OleDb.OleDbDataAdapter(sql1, con)
da1.Fill(ds1, "Address")
sql2 = "SELECT * FROM [ORDER]"
da2 = New OleDb.OleDbDataAdapter(sql2, con)
da2.Fill(ds2, "ORDER")
sql3 = "SELECT MAX(ReceiptNumber) FROM [ORDER]"
da3 = New OleDb.OleDbDataAdapter(sql3, con)
da3.Fill(ds3, "Orders")
sql4 = "SELECT * FROM DELIVERY"
da4 = New OleDb.OleDbDataAdapter(sql4, con)
da4.Fill(ds4, "Delivery")
con.Close()
txtItemCode.Text = ds.Tables("Items").Rows(ItemNumber).Item(0)
txtItemName.Text = ds.Tables("Items").Rows(ItemNumber).Item(1)
txtSize.Text = ds.Tables("Items").Rows(ItemNumber).Item(2)
txtPrice.Text = ds.Tables("Items").Rows(ItemNumber).Item(4)
txtDeliveryFee.Text = "100.00"
txtDeliveryAddress.Text = ds1.Tables("Address").Rows(0).Item(0)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frmShop.Show()
Me.Close()
End Sub
Private Sub btnBuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuy.Click
Dim today As System.DateTime
Dim deliverydate As System.DateTime
today = System.DateTime.Now
deliverydate = today.AddDays(7)
Dim cb As New OleDb.OleDbCommandBuilder(da2)
Dim dsNewRow As DataRow
Dim cb1 As New OleDb.OleDbCommandBuilder(da3)
Dim dsNewRow1 As DataRow
dsNewRow = ds2.Tables("ORDER").NewRow()
dsNewRow.Item(1) = CustomerID1
dsNewRow.Item(2) = txtItemCode.Text
dsNewRow.Item(3) = txtQuantity.Text
dsNewRow.Item(4) = txtPrice.Text
dsNewRow.Item(5) = txtDeliveryFee.Text
ds2.Tables("ORDER").Rows.Add(dsNewRow)
da2.Update(ds2, "ORDER")
lastReceiptNumber = ds3.Tables("Orders").Rows(0).Item(0)
dsNewRow1 = ds4.Tables("Delivery").NewRow()
dsNewRow1.Item(0) = lastReceiptNumber
dsNewRow1.Item(1) = txtDeliveryAddress.Text
dsNewRow1.Item(3) = deliverydate
dsNewRow1.Item(4) = "Processing"
ds4.Tables("Delivery").Rows.Add(dsNewRow1)
da4.Update(ds4, "Delivery")
MsgBox("Item Bought!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information)
End Sub
结束班
我在da2.Fill上有错误(ds2,"订单")有人可以帮我这个吗?错误是语法错误插入到语句中。我真的很感激那些有帮助的人。谢谢!
答案 0 :(得分:0)
使用命令构建器为数据适配器创建InsertCommand
,UpdatedCommand
和DeleteCommand
时,它将使用与{{1}中使用的列名相同的列名或者,如果使用通配符(*),它将从数据库表中获取列名。如果您的某个列名是保留字或包含空格或其他特殊字符,则生成的SQL将无效。有三种方法可以解决这个问题:
SelectCommand
和QuotePrefix
属性,使其转义所有列名称。如果你不能选择选项1,那么选项2绝对是其余选项的更好选择,但选项3更容易。当您使用Microsoft数据库时,您可以将这些属性设置为" ["和"]"分别