• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

databinding multiple listboxes from dataset

I have a sqldataadapter that has mulitple select statments in it. I am trying to fill three different datatables and populate 3 different list boxes from them. Problem is all list boxes are populating the first select statment only?

 
SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["xxx"].ConnectionString);
        DataSet ds = new DataSet();
        string mycomm = "select CODE, DESCRIPTION from Gen_Tables where TABLE_NAME = 'LATTE_EXP_TECH' and CODE like 'A%'; select CODE, DESCRIPTION from Gen_Tables where TABLE_NAME = 'LATTE_EXP_TECH' and CODE like 'B%'; select CODE, DESCRIPTION from Gen_Tables where TABLE_NAME = 'LATTE_EXP_TECH' and CODE like 'C%'";
        SqlDataAdapter da = new SqlDataAdapter(mycomm, myconn);
        myconn.Open();
        //ds.Tables.Add("ListA");
        da.Fill(ds, "ListA");
        //ds.Tables.Add("ListB");
        da.Fill(ds, "ListB");
        //ds.Tables.Add("ListC");
        da.Fill(ds, "ListC");

        lbA.DataSource = ds.Tables["ListA"];
        lbA.DataTextField = "Description";
        lbA.DataValueField = "Code";
        lbA.DataBind();

        lbB.DataSource = ds.Tables["ListB"];
        lbB.DataTextField = "Description";
        lbB.DataValueField = "Code";
        lbB.DataBind();

        lbC.DataSource = ds.Tables["ListC"];
        lbC.DataTextField = "Description";
        lbC.DataValueField = "Code";
        lbC.DataBind();

Open in new window

0
scisoc
Asked:
scisoc
1 Solution
 
devlab2012Commented:

SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["xxx"].ConnectionString);
        DataSet ds = new DataSet();
        string mycomm = "select CODE, DESCRIPTION from Gen_Tables where TABLE_NAME = 'LATTE_EXP_TECH' and CODE like 'A%'";
        SqlDataAdapter da = new SqlDataAdapter(mycomm, myconn);
        myconn.Open();
        //ds.Tables.Add("ListA");
        da.Fill(ds, "ListA");
mycomm = "select CODE, DESCRIPTION from Gen_Tables where TABLE_NAME = 'LATTE_EXP_TECH' and CODE like 'B%'";
da = new SqlDataAdapter(mycomm, myconn);

        //ds.Tables.Add("ListB");
        da.Fill(ds, "ListB");
        //ds.Tables.Add("ListC");

mycomm = "select CODE, DESCRIPTION from Gen_Tables where TABLE_NAME = 'LATTE_EXP_TECH' and CODE like 'C%'";
da = new SqlDataAdapter(mycomm, myconn);

        da.Fill(ds, "ListC");

        lbA.DataSource = ds.Tables["ListA"];
        lbA.DataTextField = "Description";
        lbA.DataValueField = "Code";
        lbA.DataBind();

        lbB.DataSource = ds.Tables["ListB"];
        lbB.DataTextField = "Description";
        lbB.DataValueField = "Code";
        lbB.DataBind();

        lbC.DataSource = ds.Tables["ListC"];
        lbC.DataTextField = "Description";
        lbC.DataValueField = "Code";
        lbC.DataBind();

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now