Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Users/diva/Desktop/stores.mdb");
DataSet ds = new DataSet();
System.Data.OleDb.OleDbDataAdapter da;

 con.Open();
da = new System.Data.OleDb.OleDbDataAdapter(sql1 = "SELECT * FROM  dbTableName", con);
da.Fill(ds, dbTableName);
con.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "dbTableName";


I cant able to get table from the database please help me..
Posted
Updated 18-Nov-12 22:12pm
v2

Hi, try this:
C#
string connString = 
    @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database.mdb";

DataTable results = new DataTable();

using(OleDbConnection conn = new OleDbConnection(connString))
{
    OleDbCommand cmd = new OleDbCommand("SELECT * FROM TableName", conn);

    conn.Open();

    OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);

    adapter.Fill(results);
}
Please change the DB path and table name as per yours.
 
Share this answer
 
Comments
praveen kadimi 19-Nov-12 6:55am    
thank you soo much
tanweer 19-Nov-12 7:45am    
if this solves your problem then please mark it as answer
C#
using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.Common;
using System.Data.OleDb;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (OleDbConnection oCon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\dinesht\Desktop\MyDB.mdb"))
            {
                oCon.Open();

                OleDbDataAdapter oAdpt = new OleDbDataAdapter("SELECT * FROM tbl", oCon);

                DataSet __ds = new DataSet();

                oAdpt.Fill(__ds, "tbl");

                // THE DATASET IS FILLED NOW. YOU CAN USE THE DATA //

                oCon.Close();
            }
        }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900