日期:2014-05-18  浏览次数:21194 次

提示:com.ExecuteNonQuery();语句有误(关键字 'into' 附近有语法错误。)
string sex;
  if(menRadioButton.Checked==true)
  {
  sex="男";
  }
  else
  {sex="女";}
  //if()
  //{}
  string connString = "server=陈羊阳-PC;database=C#HomeWork;Integrated Security=true";
  SqlConnection con = new SqlConnection(connString);
  string sql = "inster into [patientData] (病人编号,姓名,年龄,性别,医生,病症,类别)values('"+this.patientTextBox.Text.ToString()+"','"+
  //this.patientTextBox.Text.ToString()+"','"+
  this.nameTextBox.Text.ToString()+"','"+
  int.Parse(this.ageTextBox.Text.ToString())+"','"+
  sex+"','"+this.doctorComboBox.Text.ToString()+"','"+
  this.richTextBox.Text.ToString() +"','" + this.classComboBox.Text.ToString() + "');";

  con.Open();
  SqlCommand com = new SqlCommand(sql,con);
  com.ExecuteNonQuery();
  con.Close();
  MessageBox.Show("恭喜您添加成功!");

提示:com.ExecuteNonQuery();语句有误(关键字 'into' 附近有语法错误。)
请各位帮忙解答

------解决方案--------------------
"inster ====> insert
------解决方案--------------------
insert 写错了,还有年龄字段是int型的,不需用用''包括。

C# code

string sql = "insert  into [patientData] (病人编号,姓名,年龄,性别,医生,病症,类别) values('"+this.patientTextBox.Text.ToString()+"','"+
  this.nameTextBox.Text.ToString()+"',"+
  int.Parse(this.ageTextBox.Text.ToString())+",'"+
  sex+"','"+this.doctorComboBox.Text.ToString()+"','"+
  this.richTextBox.Text.ToString() +"','" + this.classComboBox.Text.ToString() + "')";