I want to bind a column into dropdownlist from database using datareader & dataadapter.
Plzzzzzzzz provide me the code.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Oct 14, 2013, 1:09 AM
hi,
Try following code
public SqlConnection conn = new SqlConnection("connection string");
conn.Open();
SqlCommand cmd = new SqlCommand("Select * from tableName", conn);
SqlDataReader dr = cmd.ExecuteReader();
DDList1.DataSource = dr;
DDList1.DataTextField = "TextField";
DDList1.DataValueField = "ValueField";
DDList1.DataBind();
conn.Close();
or
SqlConnection con = new SqlConnection("connection string");
con.Open();
SqlCommand cmd = new SqlCommand(sqlQ, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DDList1.DataSource = dt;
DDList1.DataTextField = "TextField";
DDList1.DataValueField = "ValueField";
DDList1.DataBind();
con.Close();
hope this will help you.