开发者

Fill a DataGrid from two different sources?

开发者 https://www.devze.com 2023-03-14 22:41 出处:网络
I have a DataGrid with 3 Columns. I would like to fill the开发者_开发知识库 first two columns from one SQL Table and the third column from a separate table. I can easily fill it from one source with a

I have a DataGrid with 3 Columns. I would like to fill the开发者_开发知识库 first two columns from one SQL Table and the third column from a separate table. I can easily fill it from one source with a DataSet from my database as shown below, does anyone know how can I use two different sources?

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);

dgUsers.DataSource = ds;
dgUsers.DataBind();

Thanks in advance for any help!


Create a business object with three properties and create those objects from your data set. Use those business objects to populate your datagrid. Standard n-tier architecture.


You need to join the two data sources. With LINQ it looks like:

var query = from row in ds
                        join row2 in ds2 on row.value equals row2.value
                        select new { row.value, row.value2, row2.value3 };
0

精彩评论

暂无评论...
验证码 换一张
取 消