“ ORA-00917:缺少逗号”和vbLf

时间:2018-09-24 06:42:32

标签: oracle ado.net

下面是我的查询,它是在.Net代码中创建的,用于插入到oracle表中。我找到了其他相关文章,但它们是不同的,因此无法回答。我在下面使用数据表创建查询。

`Public Sub UpdateOracleRecordset(dtTable As DataTable)
    Dim sql As String = String.Empty
    Dim i As Integer = 0
    sql = "insert into " + dtTable.TableName + "("
    For Each dc As DataColumn In dtTable.Columns
        sql = sql + dc.ToString() + ","
    Next
    sql = sql.TrimEnd(",") + ")" + " select "
    Dim rowVal As String = String.Empty
    For Each dtRow As DataRow In dtTable.Rows
        For Each dc As DataColumn In dtTable.Columns
            rowVal = rowVal + dtRow(dc).ToString() + ","
        Next
        rowVal = rowVal.TrimEnd(",") 
    Next

    sql = sql + rowVal
    ExecuteSQL(sql)
End Sub`

"insert into CS_INV(LOANNO,CASENUMBER,INQ_TYPE,FUP_REASON,FUP_DATE,FUP_PROM,USERID,DATA_DAT,UNIT) values ( 5735985,103550709,399,58,9/24/2018 1:37:01 AM,9/25/2018 12:00:00 AM,Anurag,9/24/2018 1:37:08 AM,1 ) "

1 个答案:

答案 0 :(得分:0)

Wenfried是正确的,我使用了准备好的声明来帮助解决问题

Dim conn As New OracleConnection(oradb)
    conn.Open()

    Dim sql As String = String.Empty
    Dim sqlValues As String = String.Empty
    Dim i As Integer = 0
    sql = "insert into " + dtTable.TableName + "("
    For Each dc As DataColumn In dtTable.Columns
        sql = sql + dc.ToString() + ","
        sqlValues = sqlValues + ":" + dc.ToString() + ","
    Next
    sql = sql.TrimEnd(",") + ")" + " values ( " + sqlValues.TrimEnd(",") + ")"

    Dim commandText = sql
    Dim Command As New OracleCommand(sql, conn)
    For Each dtRow As DataRow In dtTable.Rows
        For Each dc As DataColumn In dtTable.Columns
            Command.Parameters.Add(New OracleParameter(dc.ToString(), dtRow(dc)))
        Next
    Next

    Command.ExecuteNonQuery()
    conn.Close()