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,
Reader is readonly
and forward only that's why only first dropdonw
get filled with data and others are empty.
You can use datset
or Datatable
for same problem .
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
Dataset dsresult = cmd.ExecuteDataset();
If(dsResult !=null)
{
if(dsResult.Rows.count>0)
{
drClient.Enabled = true;
drClient.DataSource = dsResult.Tables[0] ;
drClient.DataTextField = Convert.ToString(ds.Tables[0].Columns["cname"]);
drClient.DataValueField = ds.Tables[0].Columns["clientID"] ;
drClient.DataBind();
}
}
Datareader
is connected architecture needs continuous connection and fetches one row at a time in forward mode better use dataset
which uses disconnected architecture
and can be used for retrieving data multiple times.