Solved

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

Posted on 2006-11-03
3
214 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now