读书人

C#数据库设计时老是出现这个有关问题

发布时间: 2012-02-05 12:07:14 作者: rapoo

C#数据库设计时老是出现这个问题
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注入攻击

读书人网 >其他数据库

热点推荐