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 21:59pm
Edited 18-Nov-12 22:12pm
tanweer13.5K
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 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 290
2 ClimerChinna 222
3 vikinghunter 178
4 OriginalGriff 161
0 Sergey Alexandrovich Kryukov 8,363
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web03 | 2.8.140827.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