Is it possible to display data fetched from database into an input field?
I know how to display data from database in a Textbox, but this time I want to learn and know if the same can be done using an input field. I tried it but it did not work.
I tried (.Text) and (.InnerText), both did not work.
<input type="email" runat="server" id="email_address" class="form-control" style="width: 100%;" />
public void Showdata1()
{
try
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT * FROM myTable WHERE Id = @Id";
cmd.Parameters.AddWithValue("@Id", Session["user"]);
cmd.Connection = con;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
email_address.Text = dr["email"].ToString();
// email_address.InnerText = dr["email"].ToString();
}
con.Close();
}
}
}
catch (SqlException ex)
{
string msg = "Error:";
msg += ex.Message;
throw new Exception(msg);
}
}