我正在尝试使用 vb.net 写入 access 2010 数据库。我让它工作但我不得不删除旧数据库并创建一个新数据库,而不是它不起作用。这是我的代码:
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Fortedb.accdb"
Dim cnn As New OleDbConnection(ConnString)
cnn.Open()
'Naming the new Row in Query1.
Dim newQuery1Row As FortedbDataSet.Query1Row
newQuery1Row = Me.FortedbDataSet1.Query1.NewQuery1Row()
'Making the first row the date.
newQuery1Row.ProdDate = GlobalVariables.mdbProdDate
newQuery1Row.BaleLine = GlobalVariables.mdbBaleLine
newQuery1Row.BaleNumber = GlobalVariables.mdbBaleNumber
newQuery1Row.GrossWeight = GlobalVariables.mdbGrossWeight
newQuery1Row.AirDry = GlobalVariables.mdbAirDry
newQuery1Row.InvoiceWeight = GlobalVariables.mdbInvoiceWeight
'Adding the row to the table.
Me.FortedbDataSet1.Query1.Rows.Add(newQuery1Row)
cnn.Close()
'Saving the row in Access.
Me.Query1TableAdapter.Update(Me.FortedbDataSet1.Query1)
当我创建我的新数据库时,我必须创建新的DataSet、TableAdpater,并且我还与新数据库建立了连接。我一定是忽略了什么。