【发布时间】:2015-03-06 16:26:27
【问题描述】:
所以我已经看这个太久了,我可能错过了一些东西但我无法理解什么。尝试在标题为“单元号”的第三列中添加数据库条目时收到错误消息,错误指出尝试添加时该区域的语法无效。
SqlConnection cn = new SqlConnection(global::ProjectAssessment.Properties.Settings.Default.Database1ConnectionString);
try
{
string sql = "INSERT INTO Students (Student_Id,Student_name,Unit_number,Unit_grade) values(" +textBox1.Text+ ",'" +textBox2.Text+ ",'" +textBox3.Text+ ",'" +textBox4.Text+"')";
SqlCommand exesql = new SqlCommand(sql, cn);
cn.Open();
exesql.ExecuteNonQuery();
MessageBox.Show("Student record added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.studentsTableAdapter.Fill(this.database1DataSet.Students);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cn.Close();
}
【问题讨论】: