朋友们,我正在编写从基础TextBox中提取信息,我想通过TextBox更新数据库,但是当我输入新值时,旧值并不总是保存新值
背后的代码
protected void Page_Load(object sender, EventArgs e)
{
string ID = Request.QueryString["Id"].ToString();
SqlConnection baglan = new SqlConnection(ConnectionString3);
baglan.Open();
SqlCommand com = new SqlCommand("Select * from pkategori where Id='" + ID + "'", baglan);
SqlDataReader oku = com.ExecuteReader();
if (oku.Read())
{
baslik.Text = oku["Tanim"].ToString();
detaylar.Text = oku["Detaylar"].ToString();
}
else
{
baslik.Text = "Bulunmadı";
}
}
按钮单击事件
string ust = Request.QueryString["ID"].ToString();
SqlConnection baglanti = new SqlConnection(ConnectionString3);
baglanti.Open();
string kayit = "update pkategori set Tanim=@Tanim where Id=@Id";
SqlCommand komut = new SqlCommand(kayit, baglanti);
komut.Parameters.AddWithValue("@Tanim", baslik.Text);
komut.Parameters.AddWithValue("@Id", ust);
komut.ExecuteNonQuery();
baglanti.Close();
答案 0 :(得分:2)
简单,只需将Service
中的代码包裹在myBackgroundService.stopForeground(true);
中 - 检查:
Page_Load
否则,您正在从数据库加载文本,并且将覆盖更改的值。