Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 18-Nov-12 22:59pm
Edited 18-Nov-12 23:12pm
tanweer14K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi, try this:
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.
  Permalink  
Comments
praveen kadimi at 19-Nov-12 6:55am
   
thank you soo much
tanweer akhtar at 19-Nov-12 7:45am
   
if this solves your problem then please mark it as answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
            }
        }
    }
}
  Permalink  
v2

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

  Print Answers RSS
0 ridoy 440
1 Maciej Los 414
2 DamithSL 150
3 Suvendu Shekhar Giri 150
4 Richard MacCutchan 144
0 OriginalGriff 8,033
1 DamithSL 6,179
2 Sergey Alexandrovich Kryukov 5,538
3 Maciej Los 5,508
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100