1

我有一个程序,它将数据保存到 Access 数据库中。保存到数据库的代码是:

Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\phipnasw01\users-hip$\cerns1\My Documents\Visual Studio 2010\Projects\Forte Data Gatherer\Forte Data Gatherer\Example1.accdb"
Dim cnn As New OleDbConnection(ConnString)

'Getting the character count for all variables.
GlobalVariables.mdbProdDate = Mid(GlobalVariables.stAddRec, 2, 19)
GlobalVariables.mdbBaleLine = Mid(GlobalVariables.stAddRec, 21, 3)
GlobalVariables.mdbBaleNumber = Mid(GlobalVariables.stAddRec, 33, 12)
GlobalVariables.mdbGrossWeight = Mid(GlobalVariables.stAddRec, 46, 6)
GlobalVariables.mdbAirDry = Mid(GlobalVariables.stAddRec, 53, 7)
GlobalVariables.mdbInvoiceWeight = Mid(GlobalVariables.stAddRec, 60, 8)

cnn.Open()

'Naming the new Row in Query1.
Dim newQuery1Row As Example1DataSet1.Query1Row
newQuery1Row = Me.Example1DataSet1.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.Example1DataSet1.Query1.Rows.Add(newQuery1Row)

cnn.Close()

'Saving the row in Access.
Me.Query1TableAdapter.Update(Me.Example1DataSet1.Query1)

代码运行后,程序仅将文件正确保存到调试文件夹中的访问数据库中。我需要将数据库保存到 C:\Forte\Example1.accdb 中的访问数据库

4

1 回答 1

0

Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=\\phipnasw01\users-hip$\cerns1\My Documents\Visual Studio 2010\Projects\Forte Data Gatherer\Forte Data Gatherer\Example1.accdb "

路径就在连接字符串中,您将其硬编码。只需在运行时使用SaveFileDialog或其他东西创建字符串以保存在您想要的任何位置。

于 2013-06-21T14:37:10.217 回答