---
title: "how to select row from datagridview when column have cells is empty"  
description: "how to select row from datagridview when column have cells is empty"  
author: "John fugio"  
published: 2013-07-21  
updated: 2013-07-24  
canonical: https://www.mindstick.com/forum/1347/how-to-select-row-from-datagridview-when-column-have-cells-is-empty  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# how to select row from datagridview when column have cells is empty

Hi there !how to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) from [datagridview](https://www.mindstick.com/articles/607/working-with-datagridview-in-vc-sharp) when [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) have cells is emptyI tried this but nothing workedPlease help on this [private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) void selectrow() { int i; for( i=0 ;i<dataGridView1 .Rows .Count -1;i++) { [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) row = dataGridView1.Rows[i].Cells["[Name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide)"].Value.ToString(); if (row =="") { sqlconn.Open(); string sqlquery = "select * from tbl... where id='" + dataGridView1.Rows[i].Cells\
["id"].Value.ToString() + "'"; [SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) sqlcmd = new SqlCommand(sqlquery, sqlconn); [SqlDataAdapter](https://www.mindstick.com/interview/33991/what-is-sqldataadapter) sqlda = new SqlDataAdapter(sqlcmd); [DataTable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net) dt = new DataTable(); sqlda.Fill(dt); dataGridView1.DataSource = dt; sqlconn.Close(); } \
} }

## Replies

### Reply by Manmohan Jha

```
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();                }            }                   }
```


---

Original Source: https://www.mindstick.com/forum/1347/how-to-select-row-from-datagridview-when-column-have-cells-is-empty

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
