我正在从数据库中检索数据到文本框,在更改文本框中的数据后,当我单击更新按钮时,再次上传相同的数据。这是获取数据的编码。
SqlConnection con = new SqlConnection("Data Source=ZAZIKHAN\\SQLEXPRESS;Initial Catalog=resume;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select JobTitle,CompanyName,JobFrom,JobTo,Description,ExperienceType FROM Experience where eid=3", con);
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read() && reader != null)
{
JobTitle.Text = reader["JobTitle"].ToString();
CompanyName.Text = reader["CompanyName"].ToString();
JobFrom.Text = reader["JobFrom"].ToString();
JobTo.Text = reader["JobTo"].ToString();
Description.InnerText = reader["Description"].ToString();
ExperienceType.Text = reader["ExperienceType"].ToString();
}
reader.Close();
con.Close();
}
catch (Exception ex)
{
Response.Write("<script LANGUAGE='JAVASCRIPT'>alert('" + ex + "')</script>");
}
以下是更新数据的编码。
protected void UPDATE_Click(object sender, EventArgs e)
{
Response.Write("<script LANGUAGE='JAVASCRIPT'>alert('" + JobTitle.Text + "')</script>");
try
{
SqlConnection con = new SqlConnection("Data Source=ZAZIKHAN\\SQLEXPRESS;Initial Catalog=resume;Integrated Security=True");
con.Open();
SqlCommand cmd3 = new SqlCommand("UPDATE Experience SET JobTitle ='" + JobTitle.Text + "',CompanyName ='" + CompanyName.Text + "',JobFrom ='" + DateTime.Now + "',JobTo = '" + JobTo.Text + "',Description ='" + Description.InnerText + "',ExperienceType='" + ExperienceType.Text + "' WHERE eid=3 ", con);
if (cmd3.ExecuteNonQuery() == 1)
{
Response.Write("<script LANGUAGE='JavaScript' >alert('information saved Successful')</script>");
}
else { Response.Write("<script LANGUAGE='JavaScript' >alert('sorry try again')</script>"); }
con.Close();
}
catch (Exception ex)
{
Response.Write("<script LANGUAGE='JAVASCRIPT'>alert('" + ex + "')</script>");
}
}