我正在尝试通过 C# 中的 Windows 窗体按钮更新我的数据库。当我运行我将要显示的代码时,它没有显示任何错误,但它不会更改数据库或数据网格中的数据。
private void update_Click(object sender, EventArgs e)
{
SqlConnection NewCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\ASPNET\cd\cdcwk2\cddatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand("UPDATE cdstock set cd_title='" + cdtext.Text + "', artist='" + artisttext.Text + "',genre='" + genretext.Text + "', rating=" + ratingtext.Text + ", cd_discription='" + distext.Text + "' where cd_id =" + idtext.Text + ";", NewCon);
MessageBox.Show("UPDATE cdstock set cd_title='" + cdtext.Text + "', artist='" + artisttext.Text + "',genre='" + genretext.Text + "', rating='" + ratingtext.Text + "', cd_discription='" + distext.Text + "' where cd_id ='" + idtext.Text + "'");
NewCon.Open();
cmd.ExecuteNonQuery();
NewCon.Close();
MessageBox.Show("Record Has Now Been UPDATED!!");
}