缺少Select语句的选择关键字

时间:2014-11-04 22:46:36

标签: sql database vb.net oracle visual-studio-2010

我在VBA中有以下代码,每当我尝试运行它时,都会收到一条错误消息“缺少select keyword”。

当我不想阅读任何内容时,我不明白为什么它甚至想要一个select关键字,我只想写入数据库:

Private Sub SubmitButton_Click(sender As System.Object, e As System.EventArgs) Handles          SubmitButton.Click
    SubmitButton.Enabled = False

    DeliveryDateTimePicker.CustomFormat = "yyyyMMdd"
    Dim sysdate As Date = Date.Now
    Dim XConnStr As String = "DSN=ivr.dsn; SERVER=ivr.dsn.world; UID=user; PWD=password;"

    Dim SQLString As String = "INSERT INTO sv.ivr_resched ([ORDER_NO], [PHONE_NO], [REQUESTED_DELIVERY_DATE], [RESCHEDULE_REASON], [CREATE_DATE], [CREATE_USERID], [IN_PROGRESS], [STATUS]) VALUES (@ORDER_NO, @PHONE_NO, @REQUESTED_DELIVERY_DATE, @RESCHEDULE_REASON, @CREATE_DATE, @CREATE_USERID, @IN_PROGRESS, @STATUS);"
    Dim objXConn As New OdbcConnection(XConnStr)
    Dim objCommand As New OdbcCommand(SQLString, objXConn)

    objCommand.Parameters.AddWithValue("@ORDER_NO", MSTextBox.Text)
    objCommand.Parameters.AddWithValue("@PHONE_NO", PhoneTextBox.Text)
    objCommand.Parameters.AddWithValue("@REQUESTED_DELIVERY_DATE", DeliveryDateTimePicker.Value)
    objCommand.Parameters.AddWithValue("@RESCHEDULE_REASON", ReasonComboBox.SelectedValue)
    objCommand.Parameters.AddWithValue("@CREATE_DATE", sysdate)
    objCommand.Parameters.AddWithValue("@CREATE_USERID", TransferID)
    objCommand.Parameters.AddWithValue("@IN_PROGRESS", "N")
    objCommand.Parameters.AddWithValue("@STATUS", "newrecrd")
    Try
        Using objXConn
            objXConn.Open()
            objCommand.ExecuteNonQuery()
            objXConn.Close()
        End Using
        MsgBox("Success")
        MSTextBox.Text = ""
        PhoneTextBox.Text = ""
        ReasonComboBox.SelectedValue = ""
        DeliveryDateTimePicker.Value = Date.Now
    Catch ex As Exception
        MessageBox.Show("Error: " & ex.ToString)
    End Try

    SubmitButton.Enabled = True

End Sub

您将获得任何帮助。

问题已经解决,这是工作代码:

    Private Sub SubmitButton_Click(sender As System.Object, e As System.EventArgs) Handles SubmitButton.Click
    SubmitButton.Enabled = False
    Dim sysdate As Date = Date.Now
    Dim XConnStr As String = "DSN=ivr.dsn; SERVER=ivr.dsn.world; UID=user; PWD=password;"
    Dim SQLString As String = "INSERT INTO sv.ivr_resched (ORDER_NO, PHONE_NO, REQUESTED_DELIVERY_DATE, RESCHEDULE_REASON, CREATE_DATE, CREATE_USERID, IN_PROGRESS, STATUS) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"
    Dim objXConn As New OdbcConnection(XConnStr)
    Dim objCommand As New OdbcCommand(SQLString, objXConn)

    objCommand.Parameters.Add("ORDER_NO", OdbcType.Char)
    objCommand.Parameters.Item("ORDER_NO").Value = MSTextBox.Text
    objCommand.Parameters.Add("PHONE_NO", OdbcType.Char)
    objCommand.Parameters.Item("PHONE_NO").Value = PhoneTextBox.Text
    objCommand.Parameters.Add("REQUESTED_DELIVERY_DATE", OdbcType.Char)
    objCommand.Parameters.Item("REQUESTED_DELIVERY_DATE").Value = DeliveryDateTimePicker.Value.ToString("yyyMMdd")
    objCommand.Parameters.Add("RESCHEDULE_REASON", OdbcType.Char)
    objCommand.Parameters.Item("RESCHEDULE_REASON").Value = ReasonComboBox.SelectedValue
    objCommand.Parameters.Add("CREATE_DATE", OdbcType.Date)
    objCommand.Parameters.Item("CREATE_DATE").Value = sysdate
    objCommand.Parameters.Add("CREATE_USERID", OdbcType.Char)
    objCommand.Parameters.Item("CREATE_USERID").Value = TransferID
    objCommand.Parameters.Add("IN_PROGRESS", OdbcType.Char)
    objCommand.Parameters.Item("IN_PROGRESS").Value = "N"
    objCommand.Parameters.Add("STATUS", OdbcType.Char)
    objCommand.Parameters.Item("STATUS").Value = "NEWREC"

    Try
        Using objXConn
            objXConn.Open()
            objCommand.ExecuteNonQuery()
            objXConn.Close()
        End Using
        MsgBox("Success")
        MSTextBox.Text = ""
        PhoneTextBox.Text = ""
        ReasonComboBox.SelectedValue = ""
        DeliveryDateTimePicker.Value = Date.Now
    Catch ex As Exception
        MessageBox.Show("Error: " & ex.ToString)
    End Try

    SubmitButton.Enabled = True

End Sub

2 个答案:

答案 0 :(得分:1)

在枚举列名时尝试删除括号:

Dim SQLString As String = "INSERT INTO sv.ivr_resched (ORDER_NO, ...

答案 1 :(得分:0)

尝试在字段名称周围使用双引号而不是括号。请参阅java.sql.SQLException: ORA-00928: missing SELECT keyword. when inserting record to DB using JDBC的答案。

Dim SQLString As String = "INSERT INTO sv.ivr_resched (""ORDER_NO"", ""PHONE_NO"", ""REQUESTED_DELIVERY_DATE"", ""RESCHEDULE_REASON"", ""CREATE_DATE"", ""CREATE_USERID"", ""IN_PROGRESS"", ""STATUS"") VALUES (@ORDER_NO, @PHONE_NO, @REQUESTED_DELIVERY_DATE, @RESCHEDULE_REASON, @CREATE_DATE, @CREATE_USERID, @IN_PROGRESS, @STATUS);"