4 Replies - 8563 Views - Last Post: 30 April 2013 - 08:02 PM Rate Topic: -----

#1 harishkothuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-October 12

check datatable column contain values

Posted 22 April 2013 - 03:33 AM

I have a data table which contains 3 columns and the first two columns are always same and column3 may or may not contain the values for all rows.
Please tell me how to identify this ?

I have tried the following.. but didn't work..
if ( dataTable.Select("ColumnName is NULL") == null )
{
}
else
{
}


Is This A Good Question/Topic? 0
  • +

Replies To: check datatable column contain values

#2 Amicable  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 22-April 13

Re: check datatable column contain values

Posted 22 April 2013 - 03:52 AM

You need to use
dataTable.Columns["ColumnName"]
to test a specific column.
Was This Post Helpful? 0
  • +
  • -

#3 harishkothuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-October 12

Re: check datatable column contain values

Posted 22 April 2013 - 04:51 AM

I have got solution with the below code..

DataRow[] IsExist = dtTable.Select("ColumnName =''");


Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3617
  • View blog
  • Posts: 11,269
  • Joined: 05-May 12

Re: check datatable column contain values

Posted 22 April 2013 - 05:28 AM

I hope some SQL masters jump in, but as I understand relational database, there is a difference between a column having a null value versus having not containing value. An empty string is still a value, but a null value indicates the lack of a value. It's just like you can have a column that is a DateTime field and SQL could return DBNull.Value, or it could actually return the equivalent of DateTime.MinValue. The latter is still a value, but the former is not.
Was This Post Helpful? 0
  • +
  • -

#5 Ghandi_Of_Codez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-March 13

Re: check datatable column contain values

Posted 30 April 2013 - 08:02 PM

cn.Open();
            String cmdString = "Select ColumnName FROM tableName WHERE ColumnName IS NULL;
            SqlCommand cmd2 = new SqlCommand(cmdString, cn);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1