向SQL server 数据库插入datatime类型数据报错,求解!
StringBuildersb=newStringBuilder();sb.AppendLine("insertintoStudent(LoginPwd,StudentN...
StringBuilder sb = new StringBuilder();
sb.AppendLine("insert into Student(LoginPwd,StudentName,Gender,GradeId,Phone,Address,Birthday,Email) values(");
sb.AppendFormat("'{0}',",txtPwd.Text);
sb.AppendFormat("'{0}',",txtName.Text);
string sex = rbtnFemale.Checked ? "1" : "0";
sb.AppendFormat("'{0}',",sex);
sb.AppendFormat("'{0}',",cboGrade.SelectedValue);
sb.AppendFormat("'{0}',",txtPhone.Text);
sb.AppendFormat("'{0}',",txtAddress.Text);
sb.AppendFormat("{0},",dpBirthday.Text);
sb.AppendFormat("'{0}'",txtEmail.Text);
sb.AppendLine(")");
DBHelper db = new DBHelper();
int i = db.ExecuteNonQuery(sb.ToString());
if (i>0)
{
MessageBox.Show("新增学生成功!","成功",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("新增学生失败!","失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
错误提示:
未处理SqlException
{"'年6月9日' 附近有语法错误。"} 展开
sb.AppendLine("insert into Student(LoginPwd,StudentName,Gender,GradeId,Phone,Address,Birthday,Email) values(");
sb.AppendFormat("'{0}',",txtPwd.Text);
sb.AppendFormat("'{0}',",txtName.Text);
string sex = rbtnFemale.Checked ? "1" : "0";
sb.AppendFormat("'{0}',",sex);
sb.AppendFormat("'{0}',",cboGrade.SelectedValue);
sb.AppendFormat("'{0}',",txtPhone.Text);
sb.AppendFormat("'{0}',",txtAddress.Text);
sb.AppendFormat("{0},",dpBirthday.Text);
sb.AppendFormat("'{0}'",txtEmail.Text);
sb.AppendLine(")");
DBHelper db = new DBHelper();
int i = db.ExecuteNonQuery(sb.ToString());
if (i>0)
{
MessageBox.Show("新增学生成功!","成功",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("新增学生失败!","失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
错误提示:
未处理SqlException
{"'年6月9日' 附近有语法错误。"} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询