**fetch the record from the datsbase through specified query string **
public void get_student()
{
if(Request.QueryString["empId"]!=null)
{
int id = Int32.Parse(Request.QueryString["empId"]);
sql = new SqlConnection(con);
sql.Open();
string retriew = "select * from emp where emp_id="+id;
SqlDataAdapter adapter = new SqlDataAdapter(retriew, sql);
adapter.SelectCommand.CommandType = CommandType.Text;
hfid.Value = id.ToString();
DataTable dt = new DataTable();
adapter.Fill(dt);
emp_name.Text = dt.Rows[0]["emp_name"].ToString();
emp_age.Text = dt.Rows[0]["emp_age"].ToString();
emp_email.Text = dt.Rows[0]["emp_email"].ToString();
emp_phone.Text = dt.Rows[0]["emp_phone"].ToString();
Button1.Text = "Update";
}
PropertyInfo isreadonly =typeof(System.Collections.Specialized.NameValueCollection) .GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);
// remove
this.Request.QueryString.Remove("empId");
**after fetching the records i want to update the record but it is not updating.code is executing successfully and no error is genereteding**
protected void Button1_Click(object sender, EventArgs e)
{
if(hfid.Value!=null)
{
int id = Int32.Parse(hfid.Value);
sql = new SqlConnection(con);
sql.Open();
string update = "update emp set emp_name='" + emp_name.Text + "',emp_age='" + emp_age.Text + "',emp_email='" + emp_email.Text + "',emp_phone='" + emp_phone.Text + "' where emp_id=" + id;
SqlCommand cmd = new SqlCommand(update, sql);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("emp_name", SqlDbType.VarChar).Value = emp_name.Text;
cmd.Parameters.Add("emp_age", SqlDbType.VarChar).Value = emp_age.Text;
cmd.Parameters.Add("emp_email", SqlDbType.VarChar).Value = emp_email.Text;
cmd.Parameters.Add("emp_phone", SqlDbType.VarChar).Value = emp_phone.Text;
sql.Close();
Response.Redirect("webform1.aspx");
}
}
shiva tiwari 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.