简体   繁体   中英

ora-00917 missing comma in insert statement

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')"

缺少逗号请帮帮我!!

It looks like you are missing a closing parentheses after your TO_DATE() call, which is causing your code to think that you have an extra parameter in your INSERT statement :

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

Parameterization, Not Concatenation

You really should be using parameters to avoid issues like this (in addition to the protection that they provide you against nastiness like SQL Injection. An example of what this might looks like can be seen below :

' 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM