我在mysql数据库中有多个表,我试图将一个表中的信息放入gridview中。这很容易,但有些行只是其他表中的id号。所以我的行看起来像
proposal_Line_Id,proposal_Id,day_Name,proposal_Desc,proposal_Vol,proposal_Vol_Unit, item_Id , product_Id ,proposal_Qty,proposal_Discount,proposal_Cost,proposal_Total,
粗体2是数字,是其他2个表的关键ID号
*** _items和 * ** _products是另一个表
我需要做的是用我们的名字填充我的数据表,所以我知道它的where语句或者加入,无论如何这里是我的连接
string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
MySqlConnection connection;
MySqlDataAdapter adapter;
connection = new MySqlConnection(ConnectionString);
try
{
//prepare query to get all records from items table
string query = "select * from ***_proposal_line where proposal_Id = " + b + "";
//prepare adapter to run query
adapter = new MySqlDataAdapter(query, connection);
//create a DataTable to hold the query results
DataTable dTable = new DataTable();
//get query results in dataset
adapter.Fill(dTable);
//set the BindingSource DataSource
dataGridView1.DataSource = dTable;
}
catch (MySqlException ex)
{
}
}
任何问题让我知道我会尝试更好地解释
布伦特
答案 0 :(得分:1)
至于理解这个问题,我认为你在查询中想要这样的东西并绑定到GridView。
SELECT
pl.proposal_Line_Id,
pl.proposal_Id,
pl.day_Name,
pl.proposal_Desc,
pl.proposal_Vol,
pl.proposal_Vol_Unit,
* * it.ITEMNAME * *,
* * pd.PRODUCTNAME * *,
pl.proposal_Qty,
pl.proposal_Discount,
pl.proposal_Cost,
pl.proposal_Total
FROM
* * ? ? ? _proposal_line * * pl,
* * ? ? ? _items * * it,
* * ? ? ? _products * * pd
WHERE pl.item_id = it.item_id
AND pl.product_id = pd.product_id
AND pl.proposal_id = 1