标题:怎么把两个OleDbDataAdapter 合并到一个DataTable
只看楼主
沉默的痞子
Rank: 4
等 级:贵宾
威 望:12
帖 子:96
专家分:127
注 册:2015-10-7
结帖率:45%
 问题点数:0 回复次数:1 
怎么把两个OleDbDataAdapter 合并到一个DataTable
程序代码:
public OleDbDataAdapter FindForMdb(string mdbpath,string sql)
        {
            string connstr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + mdbpath;
            OleDbConnection conn = new OleDbConnection(connstr);
            return new OleDbDataAdapter(sql, conn);
        }
private void btnFind_Click(object sender, EventArgs e)
        {
            string sql = txtFind.Text;
            int dataCount = GetMDBCount();
            OleDbDataAdapter da;
            System.Data.DataTable dt = new System.Data.DataTable();
            for (int i = 1; i < dataCount; i++)
            {
                string path = System.Windows.Forms.Application.StartupPath + "\\data" + i.ToString() + ".mdb";
                da=FindForMdb(path, sql);
                da.Fill(dt);
            }
            dataGridView1.DataSource = dt;
        }


for循环这里会出现从多个文件从的查找结果 ,怎么显示到窗体上?
搜索更多相关主题的帖子: DataTable sql Data System string 
2020-06-22 18:11
lzkpjm
Rank: 1
等 级:新手上路
威 望:1
帖 子:3
专家分:0
注 册:2014-2-6
得分:0 
回复 楼主 沉默的痞子
   public static DataTable Uion(DataTable dt1,DataTable dt2)
        {
            DataRow addRow;
            foreach(DataRow row in dt2.Rows)
            {
                addRow = dt1.NewRow();
                for (int i = 0; i < dt1.Columns.Count; i++)
                {
                    addRow[i] = row[i];
                }
                dt1.Rows.Add(addRow);
            }
            return dt1;
        }
dt1与dt2字段数量与名称应该相同
2021-09-26 07:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-502235-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.156809 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved