如何使用从多个表到GridView的数据源 [英] How To use Datasource from Multiple Table to GridView
本文介绍了如何使用从多个表到GridView的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打扰了,我要这样布局:
excuse me, I want make layout like this:
数据库结构如下:我想使用select查询从2个表中加载数据并将数据显示到gridview.到目前为止,我在互联网上找到了使用单个表的教程.请给我建议...
And the database stucture is like this: I want use select query to load data from 2 tables and show the data to the gridview.. so far, I found tutorials at internet but using single table.. Please give me suggestion...
推荐答案
您应该尝试这样的操作.
You should try something like this.
string query = @"SELECT * FROM Sales_so
Inner join Com_customer on COM_Customer.Com_customer_id = Sales_SO.Com_customer_Id";
Connection con = new Connection();
SqlDataAdapter dataAdapter = new SqlDataAdapter(query, con);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dataGridView1.ReadOnly = true;
dataGridView.DataSource = ds.tables[0];
这篇关于如何使用从多个表到GridView的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文