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. Combobox problem

Combobox problem

Scheduled Pinned Locked Moved C#
csharphelpdatabasevisual-studiowinforms
5 Posts 4 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.
  • V Offline
    V Offline
    Vibin Venugopal
    wrote on last edited by
    #1

    HI, Am trying to retreive some data into the Visual Studio C#.net (Winforms) combobox from a access database, but when i run it, i get only the first record, Please help me out. Thanks Vibin private void Form2_Load(object sender, System.EventArgs e) { int count=0, b=0; try { con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\JET PRINT LIMITED\\JET PRINT LIMITED.mdb"); da=new OleDbDataAdapter("select * from STOCKDET",con); con.Open(); ds=new DataSet(); da.Fill(ds,"STOCKDET"); comm.Connection=con; comm.CommandType=CommandType.Text; da=new OleDbDataAdapter(comm); dr=ds.Tables [0].Rows [b]; comboBox1.Items.Add (dr[1].ToString()); MessageBox.Show("data into Combobox successfuly!!!"); MessageBox.Show("Connected successfuly!!!"); } catch(Exception k) { MessageBox.Show(k.Message); } }

    G V 2 Replies Last reply
    0
    • V Vibin Venugopal

      HI, Am trying to retreive some data into the Visual Studio C#.net (Winforms) combobox from a access database, but when i run it, i get only the first record, Please help me out. Thanks Vibin private void Form2_Load(object sender, System.EventArgs e) { int count=0, b=0; try { con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\JET PRINT LIMITED\\JET PRINT LIMITED.mdb"); da=new OleDbDataAdapter("select * from STOCKDET",con); con.Open(); ds=new DataSet(); da.Fill(ds,"STOCKDET"); comm.Connection=con; comm.CommandType=CommandType.Text; da=new OleDbDataAdapter(comm); dr=ds.Tables [0].Rows [b]; comboBox1.Items.Add (dr[1].ToString()); MessageBox.Show("data into Combobox successfuly!!!"); MessageBox.Show("Connected successfuly!!!"); } catch(Exception k) { MessageBox.Show(k.Message); } }

      G Offline
      G Offline
      Gareth H
      wrote on last edited by
      #2

      You are always returning the first row...

      int count=0, b=0;
      dr=ds.Tables[0].Rows[b];
      comboBox1.Items.Add (dr[1].ToString());

      Regards, Gareth. (FKA gareth111)

      V 1 Reply Last reply
      0
      • G Gareth H

        You are always returning the first row...

        int count=0, b=0;
        dr=ds.Tables[0].Rows[b];
        comboBox1.Items.Add (dr[1].ToString());

        Regards, Gareth. (FKA gareth111)

        V Offline
        V Offline
        Vibin Venugopal
        wrote on last edited by
        #3

        Thanks for the reply Please guide me on what i should include to get all the data in that particular column.

        K 1 Reply Last reply
        0
        • V Vibin Venugopal

          Thanks for the reply Please guide me on what i should include to get all the data in that particular column.

          K Offline
          K Offline
          Kjetil Svendsen
          wrote on last edited by
          #4

          Hi. You should databind:

          Combobox1.DataSource = ds.Tables[0];
          Combobox1.DisplayMember = "Column name for column to display";
          Combobox1.ValueMember = "Column name for ID column";

          Kjetil

          1 Reply Last reply
          0
          • V Vibin Venugopal

            HI, Am trying to retreive some data into the Visual Studio C#.net (Winforms) combobox from a access database, but when i run it, i get only the first record, Please help me out. Thanks Vibin private void Form2_Load(object sender, System.EventArgs e) { int count=0, b=0; try { con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\JET PRINT LIMITED\\JET PRINT LIMITED.mdb"); da=new OleDbDataAdapter("select * from STOCKDET",con); con.Open(); ds=new DataSet(); da.Fill(ds,"STOCKDET"); comm.Connection=con; comm.CommandType=CommandType.Text; da=new OleDbDataAdapter(comm); dr=ds.Tables [0].Rows [b]; comboBox1.Items.Add (dr[1].ToString()); MessageBox.Show("data into Combobox successfuly!!!"); MessageBox.Show("Connected successfuly!!!"); } catch(Exception k) { MessageBox.Show(k.Message); } }

            V Offline
            V Offline
            Vimalsoft Pty Ltd
            wrote on last edited by
            #5

            firstly you are using a reader with a dataset and that confuses more. if you want to retrieve what is in the command object and in future you won't manipulate the data, you should use only a datareader.so you have combined dataset and a datareader. your code above can be written like this

            OleDbConnection con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\JET PRINT LIMITED\\JET PRINT LIMITED.mdb");
            OleDbDataReader dr;
            OleDbCommand comm = new SqlCommand();
            comm.Connection=con;
            comm.CommandType=CommandType.Text;
            comm.CommandText = "select * from STOCKDET";

            con.Open();

            dr=comm.ExecuteReader();

            con.Close();

            comboBox1.Datasource=dr;

            MessageBox.Show("data into Combobox successfuly!!!");

            MessageBox.Show("Connected successfuly!!!");

            Hope it helps

            Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

            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