Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop thru reader 1

Status
Not open for further replies.

jamert

Programmer
Dec 9, 2007
80
CA
How can one loop thru the read to check is any of the reader string values (all are stings) are not null. If the read return all null then i need to increment: io++
This is kinda what i mean:

foreach (string val in rdr2.)
{
if (rdr2[val].ToString().Length > 0) { io++; }
}

thanks
 
i think you would do something like
Code:
while (rdr.Read())
{
   if(rdr["col_name"] != DBNull.Value)  
       myStringVal = rdr["col_name"].ToString();
}
rdr.Close();

Age is a consequence of experience
 
How about:

Code:
foreach (string val in rdr2.)
{
if (rdr2[val].IsNull) { io++; }
}
 
it's considered best practice to limit the db connectivity. therefore i would load the reader into a datatable and dispose of the connection. then preform your logic.
Code:
DataTable results = new DataTable();
using(IDbConnection cnn = new SqlConnection())
{
   IDbCommand cmd = cnn.CreateCommand();
   cmd.Text = "select * from Foo";
   results.Load(cmd.ExecuteReader());
}
int numberOfNullRows = 0;
foreach(DataRow result in results.Rows)
{
   bool allColumnsAreNull = true;
   foreach(DataColumn column in results.Columns)
   {
      if(!row[column].IsNull) allColumnsAreNull = false;
   }
   if(allColumnsAreNull) numberOfNullRows++;
}
return numberOfNullRows;

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thanks i perfer litton1 only because the records returned are a maximum 26, much thanks jmeckley and macleod1021

Cheers!
 
Glad to help, thanks for the star!

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top