DataTable class members is the answer.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
Arunabh Nag: Here is the C# code I use to enumerate tables and columns. Let me know if you have trouble translating it and I will get back with you tomorrow. I figure a C# answer today is better than a VB.NET answer tomorrow :)
using System;
using System.Data;
using System.Data.Common;
using System.Windows.Forms;
namespace daniweb
{
public partial class frmDbSearch : Form
{
public frmDbSearch()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//if (_conn.ConnectionType == ConnectionWrapperType.ODBC)
//{
// SetTableList(@"System.Data.Odbc");
//}
//else if (_conn.ConnectionType == ConnectionWrapperType.OleDb)
//{
// SetTableList(@"System.Data.OleDb");
//}
//else if (_conn.ConnectionType == ConnectionWrapperType.SQL)
//{
// SetTableList(@"System.Data.SqlClient");
//}
//else if (_conn.ConnectionType == ConnectionWrapperType.Oracle)
//{
// SetTableList(@"System.Data.OracleClient");
//}
const string fName = @"C:\dotnetwin\dxDelete\dxSample_Q216730(1)\WebSite214\App_Data\nwind.mdb";
string connStr = BuildAccessConnectionString(fName, "Admin", string.Empty, string.Empty);
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connStr;
connection.Open();
DataTable _dtTables = connection.GetSchema("Tables");
DataTable _dtColumns = connection.GetSchema("Columns");
//At this point you have the tables, columns, views, etc.
System.Diagnostics.Debugger.Break();
}
}
public static string BuildAccessConnectionString(string Filename, string Username, string Password, string DatabasePassword)
{
return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';User Id={1};Password={2};Jet OLEDB:Database Password={3};",
Filename.Replace("'", "''"),
Username,
Password,
DatabasePassword);
}
}
}
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Also note -- you can just call connection.GetSchema() off of an existing OleDb or ODBC connection to access... its a lot less work.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Upload a sample project with your database so we can review.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
The problem is you're looking at all columns in the database, you need to be looking for all columns in a specific table. In this case you have a system table called "MSysAccessStorage" in the database and you're seeing the columns from it. Filter based on the "TABLE_NAME" column of the schema table.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735