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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 13, 2013, 9:09 PM EDT
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.