2016-03-29 136 views
0

有些身體幫助我。我無法修復這個錯誤,因爲我不知道錯誤在哪裏。我錯過了,但沒有成功。並且錯誤是ORA-00926:在cmd.ExecuteNonQuery()後C#上缺少VALUES關鍵字。ORA-00926:C上缺少VALUES關鍵字#

string strInsert = @"Insert into INFOR_STUDENT(IdStudent, NameStudent, NameClass, IdClass, BirthStudent, SexStudent) :IdStudent, :NameStudent, :NameClass, Select IdClass from Infor_Class where NameClass = :NameClass, :BirthStudent, :SexStudent";     

      OracleCommand cmd = new OracleCommand(); 
      //cmd.CommandType = CommandType.StoredProcedure; 
      cmd.CommandText = strInsert; 
      cmd.Connection = connIns; 


      OracleParameter idClassParam = cmd.Parameters.Add("IdStudent", OracleDbType.Varchar2, 
       ParameterDirection.Input); 
      idClassParam.Value = tbxIdStudent.Text; 


      OracleParameter nameClassParam = cmd.Parameters.Add("NameStudent", OracleDbType.Varchar2, 
       ParameterDirection.Input); 
      nameClassParam.Value = tbxNameStudent.Text; 


      OracleParameter Si_soParam = cmd.Parameters.Add("NameClass", OracleDbType.Varchar2, 
       ParameterDirection.Input); 
      Si_soParam.Value = ddListClass.Text; 


      OracleParameter birthStudent = cmd.Parameters.Add("BirthStudent", OracleDbType.Date, 
       ParameterDirection.Input); 
      birthStudent.Value = DateTime.ParseExact(tbxBirthSt.Text, "dd/mm/yyyy", CultureInfo.InvariantCulture); 


      OracleParameter sexStudent = cmd.Parameters.Add("SexStudent", OracleDbType.Varchar2, 
       ParameterDirection.Input); 
      sexStudent.Value = ddListSex.Text; 

      int row = cmd.ExecuteNonQuery(); 

回答

1

隨着錯誤消息表明,試圖在添加VALUES關鍵字的strInsert後您指定的表的所有列名:

string strInsert = @"Insert into INFOR_STUDENT(IdStudent, NameStudent, NameClass, IdClass, BirthStudent, SexStudent) VALUES (:IdStudent, :NameStudent, :NameClass, Select IdClass from Infor_Class where NameClass = :NameClass, :BirthStudent, :SexStudent)"; 
0
string strInsert = @"Insert into INFOR_STUDENT(IdStudent, NameStudent, NameClass, IdClass, BirthStudent, SexStudent) Values :IdStudent, :NameStudent, :NameClass, Select IdClass from Infor_Class where NameClass = :NameClass, :BirthStudent, :SexStudent"; 

您forgor的關鍵字值添加到您的查詢