DevExpress中GridControl实现主从表绑定数据

        private void BindData(GridControl gridControl, string strSql1, string strSql2)
        {
            string strConn = "";//连接数据库的字符串
            OleDbDataAdapter oleDBAdapter1 = new OleDbDataAdapter(strSql1, strConn);
            OleDbDataAdapter oleDBAdapter2 = new OleDbDataAdapter(strSql2, strConn);

            DataSet dataSet = new DataSet();
            oleDBAdapter1.Fill(dataSet, "table1Name");
            oleDBAdapter2.Fill(dataSet, "table2Name");

            dataSet.Relations.Add("relations",
                dataSet.Tables["table1Name"].Columns["column1Name"],
                dataSet.Tables["table2Name"].Columns["column2Name"]);

            gridControl.DataSource = dataSet.Tables["table1Name"];
        }
        //strSql1为table1的连接字符串
         //strSql2为table2的连接字符串
         //把table1作为主表,把table2作为从表,table1的列column1是该表的主键,在table2中的column2是外键(table1);


 

你可能感兴趣的:(数据库,String,table,dataset)