Datagridviews行数?

时间:2017-02-16 17:20:02

标签: c# datagridview

我有2个Datagridviews,dgv1和2.我如何检查dgv2是否没有“内容”或行?

例如我想这样做:如果dgv 2为“空”或没有行,则将OrderID:0001(来自dgv1)发送到存档?基本上我想删除这个订单是它的dgv2没有行或没有产品。

dgv2的内容与dgv1的主键btw有关。 enter image description here

     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;
    }

1 个答案:

答案 0 :(得分:1)

使用属性(dgv2.RowCount > 0)