此錯誤為
1.先檢查Command所下的SQL指令中是否每個參數前方都有加入冒號,如:Insert into member(member_id)values(:member_id)
2.接下來檢查是否每個Parameter所載入的位置都正確。不僅僅是順序,不能夠有多一個參數或是少一個參數,否則都會造成錯誤,例如下:
# VB.NET Code
Dim cmdQuery As String
cmdQuery = "INSERT INTO
EXAM_QUESTION
(EXAM_QUESTION_NO,EXAM_QUESTION_CONTEXT,SELECTION_1,SELECTION_2,
SELECTION_3,SELECTION_4,EXAM_ANS,EXAM_SCOPE_ID,TEACHER_ID)
VALUES('B0000001',:A,:B,:C,:D,:E,:F,:G,:H)"
Dim cmd As OracleCommand = New OracleCommand
cmd.Connection = con
cmd.CommandText = cmdQuery
Dim p2 As OracleParameter = New OracleParameter("A", OracleDbType.Varchar2, 500)
p2.Direction = Data.ParameterDirection.Input
p2.Value = EQ.ExamQuestionContext
cmd.Parameters.Add(p2)
Dim p3 As OracleParameter = New OracleParameter("B", OracleDbType.Varchar2, 100)
p3.Direction = Data.ParameterDirection.Input
p3.Value = EQ.Selection1
cmd.Parameters.Add(p3)
Dim p4 As OracleParameter = New OracleParameter("C", OracleDbType.Varchar2, 100)
p4.Direction = Data.ParameterDirection.Input
p4.Value = EQ.Selection2
cmd.Parameters.Add(p4)
Dim p5 As OracleParameter = New OracleParameter("D", OracleDbType.Varchar2, 100)
p5.Direction = Data.ParameterDirection.Input
p5.Value = EQ.Selection3
cmd.Parameters.Add(p5)
Dim p6 As OracleParameter = New OracleParameter("E", OracleDbType.Varchar2, 100)
p6.Direction = Data.ParameterDirection.Input
p6.Value = EQ.Selection4
cmd.Parameters.Add(p6)
Dim p7 As OracleParameter = New OracleParameter("F", OracleDbType.Varchar2, 5)
p7.Direction = Data.ParameterDirection.Input
p7.Value = EQ.ExamAns.ToString
cmd.Parameters.Add(p7)
Dim p8 As OracleParameter = New OracleParameter("G", OracleDbType.Varchar2, 10)
p8.Direction = Data.ParameterDirection.Input
p8.Value = ES.ExamScopeID
cmd.Parameters.Add(p8)
Dim p9 As OracleParameter = New OracleParameter("H", OracleDbType.Varchar2, 10)
p9.Direction = Data.ParameterDirection.Input
p9.Value = T.TeacherID
cmd.Parameters.Add(p9)
------------------------------------------
0 意見:
張貼留言