0

i tried using this code :

OleDbConnection c = new OleDbConnection(con);
string SQLS = "SELECT MSysObjects.Name FROM MSysObjects WHERE MSysObjects.Name Not Like 'MsyS*' AND MSysObjects.Type=1 ORDER BY MSysObjects.Name";
OleDbDataAdapter da = new OleDbDataAdapter(SQLS, c);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;

But i got this exception:

Record(s) cannot be read; no read permission on 'MSysObjects'.

Now, i need to transfer the entire ms-access database to mysql programmaticaly, thus i need the database names. How do I work my way around this error?

3 Answers 3

6
using System;
using System.Data;
using System.Data.OleDb;

public class DatabaseInfo {    
    public static void Main () { 
        String connect = "Provider=Microsoft.JET.OLEDB.4.0;data source=.\\Employee.mdb";
        OleDbConnection con = new OleDbConnection(connect);
        con.Open();  
        Console.WriteLine("Made the connection to the database");

        Console.WriteLine("Information for each table contains:");
        DataTable tables = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[]{null,null,null,"TABLE"});

        Console.WriteLine("The tables are:");
            foreach(DataRow row in tables.Rows) 
                Console.Write("  {0}", row[2]);


        con.Close();
    }
}

///taken from http://www.java2s.com/Code/CSharp/Database-ADO.net/Getalltablenames.htm

Sign up to request clarification or add additional context in comments.

Comments

1

You can access it like this:

OleDbConnection conn =
 new OleDbConnection(
    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
    "C:\\phycoaide\\phycoaide.mdb;Persist Security Info=False;");

// retrieving schema for a single table
OleDbCommand cmd = new OleDbCommand("taxa", conn);
cmd.CommandType = CommandType.TableDirect;
conn.Open();
OleDbDataReader reader =
 cmd.ExecuteReader(CommandBehavior.SchemaOnly);
DataTable schemaTable = reader.GetSchemaTable();
reader.Close();
conn.Close();

See http://harborsparrow.blogspot.com/2009/05/c-code-to-get-schema-of-access-table.html for more details.

EDIT:
Ok, so then you can retrieve all the tables using a solution like this: How do I list all the queries in a MS Access file using OleDB in C#? and then loop through them.

4 Comments

i going with this assuming i do not know what the table of the database are .
Glad I could help. Please mark this as an answer if it does the trick! :-)
but i seek different kind of answer...:)
i assume that i do not know the name of the tables in this database
0

You can try Kros.Utils.MsAccess. This package has support for MsAccess database schema.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.