how to select row from datagridview when column have cells is empty

Posted by Fugio under C# on 7/21/2013 | Points: 10 | Views : 1718 | Status : [Member] | Replies : 1
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();
}


}

}




Responses

Posted by: Nadeemshaik on: 7/22/2013 [Member] Starter | Points: 25

Up
0
Down
write like this

private void selectrow() 

{
int i;
for( i=0 ;i<dataGridView1 .Rows .Count -1;i++)
{
if (string.isNullorEmpty(dataGridView1.Rows.Cells["Name"].Value.ToString()))
{
sqlconn.Open();
string sqlquery = "select * from tbl... where id='" + dataGridView1.Rows.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();
}


}

}


Fugio, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response