简体   繁体   English

ora-00917 在插入语句中缺少逗号

[英]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()调用后缺少TO_DATE()括号,这导致您的代码认为您的 INSERT 语句中有一个额外的参数:

... 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 :您确实应该使用参数来避免此类问题(除了它们为您提供防止 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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