HOW TO SELECT ROW FROM DATAGRIDVIEW WHEN COLUMN HAVE CELLS IS EMPTY

John fugio

Total Post:1

Points:7
Posted by  John fugio
C# 
C#
 1275  View(s)
Ratings:
Rate this:
Hi there !
how to select row from datagridview when column have cells is empty
I tried this but nothing worked
Please help on this
 private void selectrow()
        {
            int i;
            for( i=0 ;i<dataGridView1 .Rows .Count -1;i++)
            {
                string row = dataGridView1.Rows[i].Cells["Name"].Value.ToString();
                if (row =="")
                {
                    sqlconn.Open();
                    string sqlquery = "select * from tbl... where id='" + dataGridView1.Rows[i].Cells

["id"].Value.ToString() + "'";
                    SqlCommand sqlcmd = new SqlCommand(sqlquery, sqlconn);
                    SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd);
                    DataTable dt = new DataTable();
                    sqlda.Fill(dt);
                    dataGridView1.DataSource = dt;
                    sqlconn.Close();
                }
               

            }
           
        }
  1. Manmohan Jha

    Post:35

    Points:245
    Re: how to select row from datagridview when column have cells is empty

    private void selectrow()
            {
                int i;
                for( i=0 ;i<dataGridView1 .Rows .Count -1;i++)
                {
                    string row = dataGridView1.Rows[i].Cells["Name"].Value.ToString();
                    if (row =="")
                    {
                        sqlconn.Open();
                        string sqlquery = "select NameE from tbl... where id='" + dataGridView1.Rows[i].Cells

    ["id"].Value.ToString() + "'";
                        SqlCommand sqlcmd = new SqlCommand(sqlquery, sqlconn);
                        SqlDataReader dr=cmd.ExecuteReader();
                        while(dr.Read())
                        {
                        dataGridView1.Rows[i].Cells["Name"].Value=dr["Name"].ToString();
                        }
                        sqlconn.Close();
                    }
                }           
            }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!