[2.0] How to get Data Tables list only from access database?
Hello friends,
I have to develop an application which will list the access database tables along with the count of the rows in front of each table.
But How to achieve this task as I am using getOledbSchemaTable method of connection object but getting unnecessary columns on my datagrid.
DataTable dt = oconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
dataGridView1.DataSource = dt;
Please give me solution .
Thanks in advance.
Re: [2.0] How to get Data Tables list only from access database?
http://davidhayden.com/blog/dave/arc...GetSchema.aspx
As for the rowcount, you'll need to do a count(*) for each table, as I doubt the schema information will return this information to you.
Re: [2.0] How to get Data Tables list only from access database?
Dear mendrek I only want to extract the table name (Table_Name) column. I'm also facing same problem in my project as that of dsuraj. The code present in the link is not giving the expected output.
waiting for reply.
Re: [2.0] How to get Data Tables list only from access database?
If it isn't the expected output, then tell us if you're getting any error messages, what output you're getting, and what you're expecting. AND the code you're running.
1 Attachment(s)
Re: [2.0] How to get Data Tables list only from access database?
Good Morning Sir.
This is my code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace CountTableRows
{
public partial class RowCount : Form
{
string file;
OleDbConnection oconn;
public RowCount()
{
InitializeComponent();
}
private void BrowseButton_Click(object sender, EventArgs e)
{
OpenFileDialog.Filter = "*.mdb(Access Files) | *.mdb";
OpenFileDialog.ShowDialog();
PathTextBox.Text = OpenFileDialog.FileName;
file = OpenFileDialog.FileName;
oconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + file + ";User Id=admin;Password=;");
}
private void TableButton_Click(object sender, EventArgs e)
{
try
{
oconn.Open();
DataTable dt = oconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
/*int i = dt.Columns.IndexOf("Table_Name"); //This code doesn't display anything
DataGridView.DataSource = dt.Columns[i];*/ //in the datagrid. Why?
DataGridView.DataSource = dt; //This code shows tables in datagrid.
}
catch (Exception tabexp)
{
MessageBox.Show(tabexp.ToString());
}
finally
{
oconn.Close();
}
}
private void CountButton_Click(object sender, EventArgs e)
{
}
}
}
I've attached the output of the program.
Thanks & Regards,
Arinjay.