Drop down list not binding with sqldatareader

前端 未结 4 1338
一个人的身影
一个人的身影 2021-01-24 10:15

i have a form with a collection of about five drop down . i have my query as follows .

 string sql = \"SELECT a.clientID ,a.[cname],b.bid,b.[bname],c.contactID,          


        
4条回答
  •  清歌不尽
    2021-01-24 10:57

    Either you will have to make a seperate reader for each binding

    or you can do this by filling a datatable ( i would prefer this). Like,

    DataTable dt = new DataTable();
    using (SqlDataAdapter a = new SqlDataAdapter(sql, connection))
    {       
       a.Fill(dt);
    }
    drClient.DataSource = dt;
    drClient.DataBind();
    drBranch.DataSource = dt;
    drBranch.DataBind();
    drContact.DataSource = dt;
    drContact.DataBind();
    drFax.DataSource = dt;
    drFax.DataBind();
    

提交回复
热议问题