是否可以将多个数据库连接到程序?
我添加了一个数据库,但它始终通过"数据源配置向导"。我的应用程序处理一个主数据库,但我需要从其他数据库加载信息并将其添加到主数据库(用户将通过OpenFileDialog选择哪个数据库)。
Public Class Form1
Private Sub TblTestBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblTestBindingNavigatorSaveItem.Click
Me.Validate()
Me.TblTestBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.TestdbDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'TestdbDataSet.tblTest' table. You can move, or remove it, as needed.
Me.TblTestTableAdapter.Fill(Me.TestdbDataSet.tblTest)
End Sub
Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
Dim DBConnection As New OleDb.OleDbConnection
'''' Dim con As New OleDb.OleDbConnection
Dim dbProvider As String = "Provider=Microsoft.ACE.OLEDB.12.0;"
'Dim dbSource As String = opnFile.ShowDialog()
opnFile.ShowDialog()
Dim ex As String = opnFile.FileName
MessageBox.Show(ex)
Dim dbSource As String = "DataSource=" & ex
MessageBox.Show(dbSource, "Data Source String", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Dim DBDataSet As New DataSet
'''' Dim ds As New DataSet
Dim DBDataAdapter As OleDb.OleDbDataAdapter
'''' Dim da As OleDb.OleDbDataAdapter
DBConnection.ConnectionString = dbProvider & dbSource
'DBDataAdapter = (sql, DBConnection)
End Sub
End Class
另外,有人可以向我解释DataAdapter,DataConnection和DataSet中的链接吗?从我看来,DataConnection只是将应用程序连接到数据库的链接。 DataSet是数据库中的实际数据。那么DataAdapter是什么?
感谢您的帮助!
答案 0 :(得分:0)
您可以使用数据库向导添加多个数据库。您将缺少绑定导航器,但您可以通过在项目中创建临时表单来轻松地将数据库添加到此,然后在删除临时表单之前复制绑定导航器。
答案 1 :(得分:0)
请参阅此主题Display data from access using dataset使用以下内容。
将表格加载到数据集
后尝试这样的操作For Each row1 In (From dr As DataRow In yourDataSet.Tables(0).Rows Select dr Where dr("Column_Name").ToString.StartsWith(yourstring)
somestring = row1("Column_Name").ToString