FutureDev
FutureDev

Reputation: 155

Datagridviews row count?

I have this 2 Datagridviews, dgv1 and 2. How can i check if dgv2 has no "content" or rows?

For example i want to do: Send OrderID: 0001(from dgv1) to archives if dgv 2 is "empty" or no rows? basically i want to remove this Order is its dgv2 has no rows or no products left.

dgv2's content is related to dgv1's primary key 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;
    }

Upvotes: 0

Views: 670

Answers (1)

sofsntp
sofsntp

Reputation: 2164

use the property (dgv2.RowCount > 0)

Upvotes: 1

Related Questions