我有2个Datagridviews,dgv1和2.我如何检查dgv2是否没有“内容”或行?
例如我想这样做:如果dgv 2为“空”或没有行,则将OrderID:0001(来自dgv1)发送到存档?基本上我想删除这个订单是它的dgv2没有行或没有产品。
private void dgvReceiving_CellClick(object sender, DataGridViewCellEventArgs e)
{
using (SqlConnection connection = new SqlConnection("Data Source=DESKTOP-MQKIBSK\\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True"))
{
SqlCommand command =
new SqlCommand("select OrderID,SupplierName,LeadTime,OrderedBy,DateOrdered,Status,DateToReceived from Orders where OrderID = '" + dgvReceiving.CurrentRow.Cells[0].Value.ToString() + "'", connection);
connection.Open();
SqlDataReader read = command.ExecuteReader();
while (read.Read())
{
rorderid.Text = (read["OrderID"].ToString());
rsupplier.Text = (read["SupplierName"].ToString());
rleadtime.Text = (read["LeadTime"].ToString());
rordered.Text = (read["OrderedBy"].ToString());
rdateordered.Text = (read["DateOrdered"].ToString());
rdatedelivery.Text = (read["DateToReceived"].ToString());
rstatus.Text = (read["Status"].ToString());
}
SqlConnection cn2 = new SqlConnection("Data Source=DESKTOP-MQKIBSK\\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True");
cn2.Open();
string amt = "select sum(TotalPrice) from Orders_productholder where OrderID = '" + rorderid.Text + "'";
SqlCommand cmd2 = new SqlCommand(amt, cn2);
labelsupertotal.Text = "P "+cmd2.ExecuteScalar().ToString();
}
dgvreceivingproduct();
}
private void dgvreceivingproduct()
{
SqlConnection cn3 = new SqlConnection("Data Source=DESKTOP-MQKIBSK\\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True");
cn3.Open();
string qry = "Select Status,ID,ProductID,ProductName,Dosage,Price,QtyOrdered,TotalPrice,ExpirationDate,SellingPrice,BatchNumber from Orders_productholder where Status = 'Unreceived' and OrderID = '" + dgvReceiving.CurrentRow.Cells[0].Value.ToString() + "' ";
SqlCommand cmd3 = new SqlCommand(qry, cn3);
DataTable poholder = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(cmd3);
adapter.Fill(poholder);
dgvReceivingproducts.DataSource = poholder;
}
答案 0 :(得分:1)
使用属性(dgv2.RowCount > 0)