Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. setting datasource of Grid View Problem

setting datasource of Grid View Problem

Scheduled Pinned Locked Moved C#
helpcss
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shaina2231
    wrote on last edited by
    #1

    i m using following code to set Datasource of gridview but its not working plz help

    string path = Directory.GetCurrentDirectory();
    string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\cricketdb.mdb";

            OleDbConnection con = new OleDbConnection(conn);
    
            OleDbCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT \* FROM countryinfo";
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet("countryinfo");
            OleDbCommandBuilder oldbcbr = new OleDbCommandBuilder(da);
            da.Fill(ds, "countryinfo");
    
            dataGridView1.DataSource = ds;
    
            
    
            comboBox2.DataSource = ds.Tables\["Country\_Name"\];
            listBox1.DataSource = ds.DefaultViewManager;
            listBox1.DisplayMember = "Country\_Name";
            dataGridView1.DataSource = ds;
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            comboBox2.DataSource = dt;
    

    Its also not setting datasource of anycontrol like combo or list plz help

    K 2 Replies Last reply
    0
    • S shaina2231

      i m using following code to set Datasource of gridview but its not working plz help

      string path = Directory.GetCurrentDirectory();
      string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\cricketdb.mdb";

              OleDbConnection con = new OleDbConnection(conn);
      
              OleDbCommand cmd = con.CreateCommand();
              cmd.CommandType = CommandType.Text;
              cmd.CommandText = "SELECT \* FROM countryinfo";
              OleDbDataAdapter da = new OleDbDataAdapter(cmd);
              DataSet ds = new DataSet("countryinfo");
              OleDbCommandBuilder oldbcbr = new OleDbCommandBuilder(da);
              da.Fill(ds, "countryinfo");
      
              dataGridView1.DataSource = ds;
      
              
      
              comboBox2.DataSource = ds.Tables\["Country\_Name"\];
              listBox1.DataSource = ds.DefaultViewManager;
              listBox1.DisplayMember = "Country\_Name";
              dataGridView1.DataSource = ds;
              DataTable dt = new DataTable();
              da.Fill(dt);
              dataGridView1.DataSource = dt;
              comboBox2.DataSource = dt;
      

      Its also not setting datasource of anycontrol like combo or list plz help

      K Offline
      K Offline
      Khaniya
      wrote on last edited by
      #2

      Is it shows any error ?

      Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim So Smile Please

      S 1 Reply Last reply
      0
      • K Khaniya

        Is it shows any error ?

        Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim So Smile Please

        S Offline
        S Offline
        shaina2231
        wrote on last edited by
        #3

        No it does not compiles any error but display nothing in gridview

        1 Reply Last reply
        0
        • S shaina2231

          i m using following code to set Datasource of gridview but its not working plz help

          string path = Directory.GetCurrentDirectory();
          string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\cricketdb.mdb";

                  OleDbConnection con = new OleDbConnection(conn);
          
                  OleDbCommand cmd = con.CreateCommand();
                  cmd.CommandType = CommandType.Text;
                  cmd.CommandText = "SELECT \* FROM countryinfo";
                  OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                  DataSet ds = new DataSet("countryinfo");
                  OleDbCommandBuilder oldbcbr = new OleDbCommandBuilder(da);
                  da.Fill(ds, "countryinfo");
          
                  dataGridView1.DataSource = ds;
          
                  
          
                  comboBox2.DataSource = ds.Tables\["Country\_Name"\];
                  listBox1.DataSource = ds.DefaultViewManager;
                  listBox1.DisplayMember = "Country\_Name";
                  dataGridView1.DataSource = ds;
                  DataTable dt = new DataTable();
                  da.Fill(dt);
                  dataGridView1.DataSource = dt;
                  comboBox2.DataSource = dt;
          

          Its also not setting datasource of anycontrol like combo or list plz help

          K Offline
          K Offline
          Khaniya
          wrote on last edited by
          #4

          shaina2231 wrote:

          comboBox2.DataSource = ds.Tables["Country_Name"];

          what is Country_Name ? I think you have to use instead

          comboBox2.DataSource = ds.Tables[0];

          :)

          Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim So Smile Please

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups