现有两个结构完全相同的Access数据库,我需要同时对这两个数据库进行添加删除修改操作,数据修改必须是修改这两个库,告诉我合并库的请绕行。我要知道的是,代码,提供思路的请绕行。谢谢。
见下面的代码,自己换成真实的数据库及表即可
Imports System.Data这个方法我只能用于添加修改删除,请问,查询数据并且绑定到DGV怎么做?
追答Public Function Search(ByVal cn1 As OleDb.OleDbConnection, ByVal cn2 As OleDb.OleDbConnection, ByVal str_cmd1 As String, ByVal str_cmd2 As String, ByVal DGV1 As DataGridView, ByVal DGV2 As DataGridView) As Boolean '查询 str_cmd1,str_cmd2---查询命令,DGV1,DGV2---DataGridView,用来显示数据的控件
Dim tb1 As New DataTable
Dim tb2 As New DataTable
Try
Dim ap1 As New OleDb.OleDbDataAdapter(str_cmd1, cn1)
ap1.Fill(tb1)
DGV1.DataSource = tb1
Dim ap2 As New OleDb.OleDbDataAdapter(str_cmd2, cn2)
ap2.Fill(tb2)
DGV2.DataSource = tb2
Return True
Catch ex As Exception
MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
你好,我是要合并数据放在一个DGV里面的。
追答Public Function Search(ByVal cn1 As OleDb.OleDbConnection, ByVal cn2 As OleDb.OleDbConnection, ByVal str_cmd1 As String, ByVal str_cmd2 As String, ByVal DGV As DataGridView) As Boolean '查询 str_cmd1,str_cmd2---查询命令,DGV---DataGridView,用来显示数据的控件
Dim tb1 As New DataTable
Dim tb2 As New DataTable
Try
Dim ap1 As New OleDb.OleDbDataAdapter(str_cmd1, cn1)
ap1.Fill(tb1)
Dim ap2 As New OleDb.OleDbDataAdapter(str_cmd2, cn2)
ap2.Fill(tb2)
For i = 0 To tb2.Rows.Count - 1
tb1.Rows.Add(tb2.Rows(i))
Next
DGV.DataSource = tb1
Return True
Catch ex As Exception
MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
Public Function Search(ByVal cn1 As OleDb.OleDbConnection, ByVal cn2 As OleDb.OleDbConnection, ByVal str_cmd1 As String, ByVal str_cmd2 As String, ByVal DGV As DataGridView) As Boolean '查询 str_cmd1,str_cmd2---查询命令,DGV1,DGV2---DataGridView,用来显示数据的控件
Dim tb1 As New DataTable
Dim tb2 As New DataTable
Try
Dim ap1 As New OleDb.OleDbDataAdapter(str_cmd1, cn1)
ap1.Fill(tb1)
Dim ap2 As New OleDb.OleDbDataAdapter(str_cmd2, cn2)
ap2.Fill(tb2)
For i = 0 To tb2.Rows.Count - 1
tb1.Rows.Add(tb2.Rows(i).ItemArray)'这里变了
Next
DGV.DataSource = tb1
Return True
Catch ex As Exception
MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
分肯定是你的了,但我真心是想跟你交朋友。与智者同行。
追答我是搞自动化开发的,vb.net是自学的,皮毛而已
追问我是个还没毕业的大学生,现在在公司实习。如不嫌弃,交个朋友吧
追答只要你申请,都是会添加的
两个库同时操作,我想不通,我是新手,给点代码和建议好吗?
追答不好意思, 我已经绕道了, 不用送我~~
追问不送