我正在使用以下代码进行编辑功能。当我输入值时,它不会显示任何错误,但不会将新值保存在数据库中。INSERT 和 UPDATE 命令都不起作用。
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Omer\\Documents\\Visual Studio 2010\\WebSites\\WAPPassignment\\App_Data\\LoginStuff.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd;
SqlDataReader dr;
protected void imgbtnENFN_Click(object sender, ImageClickEventArgs e)
{
pnENFN.Visible = false;
lblENFN.Text = txtENFN.Text;
}
protected void imgbtnENLN_Click(object sender, ImageClickEventArgs e)
{
pnENLN.Visible = false;
lblENLN.Text = txtENLN.Text;
}
protected void Button3_Click(object sender, EventArgs e)
{
con.Open();
// cmd = new SqlCommand("UPDATE WhatTypes SET [First Name]='" + lblENFN.Text + "',[Last Name]='" + lblENLN.Text + "',[TP Number]='" + lblNTPn.Text + "',Email='" + lblENEm.Text + "',UserName='" + lblENUN.Text + "',Password='" + lblENP.Text + "',UserLevel='"+ lblEUL.Text+"Where UserName='" + txtAEUNS.Text+"')", con);
cmd = new SqlCommand("Insert into WhatTypes([First Name], [Last Name], [TP Number], Email, UserName, Password, UserLevel) Values ('" + lblENFN.Text + "','" + lblENLN.Text + "','" + lblNTPn.Text + "','" + lblENEm.Text + "', '" + txtEUN.Text + "', '" + lblENP.Text + "','" + lblEUL.Text+"'Where UserName = '"+txtAEUNS.Text+"' )", con);
cmd.ExecuteNonQuery();
con.Close();
}