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. error in combobox databinding

error in combobox databinding

Scheduled Pinned Locked Moved C#
databasehelp
3 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
    swtlibra
    wrote on last edited by
    #1

    i m trying to fill the combo box with the data from the access database but i m getting the error "Object reference not set to an instance of an object." i m writing the following code for the purpose

    con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=practicedatabase.accdb");
    con.Open();
    string qry = "Select * from cat_table";
    dadapter = new OleDbDataAdapter(qry, con);
    dset = new DataSet();
    DataTable dt = new DataTable("cat_table");
    dadapter.Fill(dt);
    this.comboBox1.DataSource = dt;
    this.comboBox1.DisplayMember = dt.Columns[1].ColumnName;

    T 1 Reply Last reply
    0
    • S swtlibra

      i m trying to fill the combo box with the data from the access database but i m getting the error "Object reference not set to an instance of an object." i m writing the following code for the purpose

      con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=practicedatabase.accdb");
      con.Open();
      string qry = "Select * from cat_table";
      dadapter = new OleDbDataAdapter(qry, con);
      dset = new DataSet();
      DataTable dt = new DataTable("cat_table");
      dadapter.Fill(dt);
      this.comboBox1.DataSource = dt;
      this.comboBox1.DisplayMember = dt.Columns[1].ColumnName;

      T Offline
      T Offline
      thatraja
      wrote on last edited by
      #2

      Trace & check the value dt.Columns[1].ColumnName at the following line

      this.comboBox1.DisplayMember = dt.Columns[1].ColumnName;

      Sample Code

      comboBox1.DataSource = dt;//Datasource to be bind (Ex. cat_table data)
      comboBox1.DisplayMember = "Cat_Name";//The Column to be displayed (Ex. Cat_Name)

      thatraja


      Tips/Tricks|Brainbench certifications|Facebook|Twitter

      S 1 Reply Last reply
      0
      • T thatraja

        Trace & check the value dt.Columns[1].ColumnName at the following line

        this.comboBox1.DisplayMember = dt.Columns[1].ColumnName;

        Sample Code

        comboBox1.DataSource = dt;//Datasource to be bind (Ex. cat_table data)
        comboBox1.DisplayMember = "Cat_Name";//The Column to be displayed (Ex. Cat_Name)

        thatraja


        Tips/Tricks|Brainbench certifications|Facebook|Twitter

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

        but it still giving the same error

        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