Solved

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

Posted on 2006-11-03
3
215 Views
Last Modified: 2010-04-16
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;                        
            }
0
Comment
Question by:JakeyCakes
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
DrAske earned 500 total points
ID: 17868770
have you tried this??
Records = Tables[tbl].Rows.Count;
0
 
LVL 9

Expert Comment

by:DrAske
ID: 17868823
Ooooh !! forget about my post .. I don't know why I thought *Tables* is a dataset!!

0
 

Author Comment

by:JakeyCakes
ID: 17994656
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)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question