Link to home
Start Free TrialLog in
Avatar of JakeyCakes
JakeyCakes

asked on

Modify Access Table code to also return the number of records in the specified table

Hi how could I modify my code below so it also returns the number of records in the table specified? Please help!

public bool TableExist(string tbl)//tbl indicates the name of the table
            {
                  OleDbConnection conn = new OleDbConnection();
                  conn.ConnectionString =
                        @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=" + Access;    
                  conn.Open();
                  System.Data.DataTable Tables = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null,null,null,"TABLE"});              
                  



                  System.Data.DataRow[] dr = null;
                  
                  dr = Tables.Select("TABLE_NAME = '" + tbl + "'");  
                  
               
                  if (dr.Length <=0)
                        return false; //if table is not found return false
                  else
                        
                  //Problem line ==>Records = Tables.Rows.Count //integer Records should contain the number of records in the table tbl. This returns the number of tables in the database which is what I do not want
                        return true;                        
            }
ASKER CERTIFIED SOLUTION
Avatar of DrAske
DrAske
Flag of Jordan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ooooh !! forget about my post .. I don't know why I thought *Tables* is a dataset!!

Avatar of JakeyCakes
JakeyCakes

ASKER

DrAske Apologies for the lengthy delay in giving you the points - I have been extremely busy at work (for which I use this site for)