Solved

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

Posted on 2006-11-03
3
213 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
Comment Utility
have you tried this??
Records = Tables[tbl].Rows.Count;
0
 
LVL 9

Expert Comment

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

0
 

Author Comment

by:JakeyCakes
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

13 Experts available now in Live!

Get 1:1 Help Now