【发布时间】:2024-01-10 08:49:01
【问题描述】:
我的 SQL 数据库中有四个表
在 C# 中,我创建了一个 datagridview,它显示了在 select 语句中连接的 Order、Linkedtable 和 Stock 表中的 DeliveryDate、Quantity、Description 和 Price。
这里是将三个表连接成一个datagridview的代码
// this code for the load button of the datagridview
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("SELECT O.DeliveryDate, L.Quantity, S.Description, S.Price FROM [Order] O JOIN Linkedtable L ON O.OrderID = L.OrderID JOIN Stock S ON S.StockID = L.StockID ORDER BY O.DeliveryDate ", con);
DataTable DATA = new DataTable();
sda.Fill(DATA);
dataGridView1.DataSource = DATA;
con.Close();
我想将 DeliveryDate、Quantity、Description 和 price 从四个文本框插入到 datagridview 中,但我不知道如何像使用 SELECT 语句那样连接表来执行 INSERT 语句,有没有办法做这个?
【问题讨论】:
标签: c# sql-server datagridview