本文介绍了如何在SQL更新表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试更新在SQL数据库中的表Student_Course,它运行,但我不断收到
I really just need to update the marks value but need to match it to the CID (Course ID) and SID(Student ID)
private void btnAdd_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(cs))
{
try
{
using (var cmd = new SqlCommand("UPDATE Student_Course SET CID=@CID, SID=@SID , Mark=@Mark", con))
{
cmd.Connection = con;
con.Open();
cmd.Parameters.AddWithValue("@CID", cboCID.GetItemText(cboCID.SelectedItem));
cmd.Parameters.AddWithValue("@SID", cboSID.GetItemText(cboSID.SelectedItem));
cmd.Parameters.AddWithValue("@Mark", Convert.ToInt32(txtMark.Text));
if (cmd.ExecuteNonQuery() > 0)
{
MessageBox.Show("Mark Added");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error during insert: " + ex.Message);
}
}
}
解决方案
"UPDATE Student_Course SET Mark = @Mark WHERE CID=@CID AND SID=@SID"
This should be the correct SQL statement because you are trying to update the Mark
field in your Student_Course
table based on the CID
& SID
of the person.
这篇关于如何在SQL更新表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!