ora-00917在insert语句中缺少逗号

时间:2016-05-27 16:41:33

标签: sql vb.net oracle

Dim sql As String = "INSERT INTO service VALUES ( '', '" & ComboBox1.Text & "', '" & ListBox1.Text & "', '" & ListBox2.Text & "',  '" & ListBox3.Text & "', '" & ComboBox2.Text & "', '" & ListBox6.Text & "', '" & ListBox5.Text & "', '" & ListBox4.Text & "', TO_DATE('" & DateTimePicker1.Text & "', 'dd-MM-YYYY')"

缺少逗号请帮帮我!!

1 个答案:

答案 0 :(得分:1)

看起来你在TO_DATE()调用后错过了一个右括号,这导致你的代码认为你的INSERT语句中有一个额外的参数:

... TO_DATE('" & DateTimePicker1.Text & "', 'dd-MM-YYYY'))"

参数化,非连接

你真的应该使用参数来避免这样的问题(除了它们为你提供的保护,如SQL注入这样的肮脏。这可能是一个例子,如下所示:

' Build your connection '
Using connection As New OracleConnection("{your-connection-string}")
     ' Build your query (using parameters) '
     Dim query = Dim sql As String = "INSERT INTO service VALUES ('', @combo1, @list1, @list2, @list3, @combo2, @list6, @list5, @list4, @date)"

     ' Build a command to execute '
     Using command As New OracleCommand(query, connection)
         ' Open your connection '
         connection.Open()
         ' Add your parameters '
         command.Parameters.AddWithValue("@combo1",ComboBox1.Text)
         command.Parameters.AddWithValue("@list1",ListBox1.Text)
         ' More omitted for brevity '
         command.Parameters.AddWithValue("@date", DateTime.ParseExact(DateTimePicker1.Text,"dd-MM-yyyy", Nothing))

         ' Execute your command '
         command.ExecuteNonQuery()
     End Using
End Using