Hi,

I don't under what I'm doing wrong. In my line of code I have 2 outputs: The first outout returns a value, however, when I try to output the second ConsoleLine I get a value of "0"??

I'm thinking it has something to do with Converting a string to int? Any Ideas?

OleDbCommand myOleDbCommand_MemCount = myOleDbConnection.CreateCommand();
myOleDbCommand_MemCount.CommandText = "Select COUNT(emp) FROM temp_table)";

OleDbDataReader myOleDbDataReader_MemCount = myOleDbCommand_MemCount.ExecuteReader();
myOleDbDataReader_MemCount.Read();

Console.WriteLine("Number of Members: " + myOleDbDataReader_MemCount["COUNT(emp)"]);

int Count = myOleDbDataReader_MemCount.GetOrdinal("COUNT(emp)");
Console.WriteLine(Count);

myOleDbDataReader_MemCount.Close();

Try changing your code to this:

OleDbCommand myOleDbCommand_MemCount = myOleDbConnection.CreateCommand();
myOleDbCommand_MemCount.CommandText = "Select COUNT(emp) [B]as empCount[/B] FROM temp_table)";
 
OleDbDataReader myOleDbDataReader_MemCount = myOleDbCommand_MemCount.ExecuteReader();
if ( myOleDbDataReader_MemCount.Read() )
{
 
Console.WriteLine("Number of Members: " +   
       myOleDbDataReader_MemCount["empCount"].ToString() );
 
  int Count = (int)myOleDbDataReader_MemCountl["empCount"];
Console.WriteLine(Count); 
 
  myOleDbDataReader_MemCount.Close(); 
}

You can also just use the 0 index since you know you are only going to return one column from the aggregate SQL statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.