namespace Exercise
{
public partial class alterGrade : Form
{
string strCon = "Data Source=.;Initial Catalog=地信学分统计;Integrated Security=true";
SqlConnection con3;
public alterGrade()
{
InitializeComponent();
con3 = new SqlConnection(strCon);
}
private void alterButton_Click(object sender, EventArgs e)
{
string upsql = "update gradeInformation set 学分= 'gradeTextBox.Text' where 姓名='"+nameTextBox.Text+"' and 学号='"+gradeTextBox.Text+"'";
SqlCommand cmd = new SqlCommand(upsql, con3);
con3.Open();
cmd.ExecuteNonQuery();
con3.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
提醒“从数据类型 varchar 转换为 float 时出错”,求高手指点!
------解决方案--------------------------------------------------------
string upsql = "update gradeInformation set 学分= 'gradeTextBox.Text' where 姓名='"+nameTextBox.Text+"' and 学号='"+gradeTextBox.Text+"'";
学号的数据类型不正确 把学号后面的单引号删掉
还有 查询字符串不要这样写 防止SQL注入攻击