Still learning here...
this is my method to get the record count of a table ... it works, but it seems like a lot of coding for something so simple.
Is there an easier way?
public int GetTableRecCount(string table)
{
//Set up the connection and adapters...
OleDbConnection myConn = new OleDbConnection();
myConn.ConnectionString = strConnStr;
OleDbCommand sqlCmd = new OleDbCommand("SELECT COUNT(*) FROM " + table);
OleDbDataAdapter dbAdapter = new OleDbDataAdapter();
dbAdapter.SelectCommand = sqlCmd;
DataSet ds = new DataSet();
ds.Clear();
// Open the connection ....
myConn.Open();
sqlCmd.Connection = myConn;
// Get the data and see how many records we got ....
dbAdapter.Fill(ds, "count");
string tmpStr = ds.Tables[0].Rows[0][0].ToString();
// Close the connection and toss it...
myConn.Close();
myConn.Dispose();
return int.Parse(tmpStr);
}
I'm still a little shakey on the dataset stuff, and retreiving the value to a string, and then parsing it was the only way I could get it to work. When I tied;
return int.Parse(ds.Tables[0].Rows[0][0].ToString());
or
return ds.Tables[0].Rows[0][0];
... the compiler whined at those two attempts, and the build failed. I'm not sure why, but I'm not stressing over it either.
Just looking for mentoring ... thanks in advance guys.