Reputation: 399
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?
Upvotes: 0
Views: 6439
Reputation: 325
You can try Kros.Utils.MsAccess. This package has support for MsAccess database schema.
Upvotes: 0
Reputation: 399
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
Upvotes: 6
Reputation: 3539
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.
Upvotes: 1