Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

830 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