How to display database records in textbox on page load
how to display database records in textbox on page load in asp.net
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
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
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 14, 2015, 11:26 PM EDT
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("select * from table where Id='" + value + "'", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Id",value);
cmd.Connection = con;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox1.Text = dr["username"].ToString();
TextBox2.Text = dr["password"].ToString();
TextBox3.Text = dr["fname"].ToString();
TextBox4.Text = dr["gender"].ToString();
}
dr.Close();
con.Close();