数据库只保存到调试文件夹

时间:2013-06-21 14:31:07

标签: .net

我有一个程序,它将数据保存到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

中的访问数据库

1 个答案:

答案 0 :(得分:0)

  

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

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