source code to fetch data from database to combobox using databinding in c#.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharathk27
    New Member
    • May 2010
    • 16

    source code to fetch data from database to combobox using databinding in c#.net

    Code:
    SqlConnection con1 = new SqlConnection("Data Source =(local); Initial Catalog=cyberstations; Integrated Security=sspi;");
    con1.Open();
    string str1 = "select systemname from terminals where systemstatus='0'";
    SqlCommand cmd1 = new SqlCommand(str1, con1);
    SqlDataAdapter adp1 = new SqlDataAdapter();
    DataSet ds1 = new DataSet();
    adp1.SelectCommand = cmd1;
    adp1.SelectCommand.ExecuteNonQuery();
    adp1.Fill(ds1);
    combobox1.DataSource = ds1.Tables[0];
    combobox1.DisplayMember = "systemname";
    combobox1.ValueMember = "systemname";
    con1.Close();

    here systemstatus used to check the condition. and systemname is the column which must be displayed in combobox.

    this code works fine in microsoft visual studio 2005
    edit reply report
    Last edited by Curtis Rutland; Aug 6 '10, 03:52 PM. Reason: use [CODE][/CODE] tags when posting code.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    I've moved this thread to the "Writing Room" area. There are a few issues you need to work out before I move this back to the Insights section.

    There are two existing insights on using Databases in your .NET programs.



    If you feel that you have something to add to them, please edit this post with the extra information.

    Comment

    Working...