Results 1 to 5 of 5

Thread: [2.0] How to get Data Tables list only from access database?

  1. #1

    Thread Starter
    Lively Member dsuraj's Avatar
    Join Date
    Nov 2007
    Location
    Pune
    Posts
    70

    Question [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.
    "Remember there is always someone who knows more than us out there"

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3
    New Member Arinjay's Avatar
    Join Date
    Mar 2008
    Posts
    5

    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.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  5. #5
    New Member Arinjay's Avatar
    Join Date
    Mar 2008
    Posts
    5

    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.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width