We can get all the table names from the .mdb file using the following code.
Name spaces used
using System; using System.Data; using System.Data.OleDb;
Code part
public class DatabaseInfo { public static void Main () { String MyConnectionsting = "Provider=Microsoft.JET.OLEDB.4.0;data source=.\\Portel.mdb";
OleDbConnection MyOleDbConnection = new OleDbConnection(MyConnectionsting); MyOleDbConnection.Open(); Console.WriteLine("Database Connection opened"); DataTable MyDataTable = MyOleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[]{null,null,null,"TABLE"});
Console.WriteLine("Following are the details of the tables in Porter.mdb"); foreach(DataRow MyDataRow in MyDataTable.Rows) { Console.Write(" {0}", MyDataRow[2]); } MyOleDbConnection.Close(); } }
Code Explanation
1. Create the instance of the OleDbConnection using connectionsting 2. open the connection 3. Create the Datatable by getting all the table details 4. By fetching the eath datarow of the data table we can get the table details of the database
By Nathan
|
No responses found. Be the first to respond and make money from revenue sharing program.
|