0

您好,我尝试编写一个应用程序,该应用程序将从 csv 文件读取的数据表插入到 sql 数据表中。

在文本下,您会看到一个获取查询字符串的函数、ConnectionString 的信息和一个用 ca 填充的数据表。900 行。传递的表具有与 sql 数据库中的相似名称完全相同的三列。唯一的区别是传递的表没有第一列,它是自动递增的主键。

它工作正常,直到这一行:mMainDbAdapter.Update(dt_Import)
抛出一个 Excpetion,在“-”附近显示错误的语法。但我没有 - 在我的 SQL 查询中?!

Public Shared Function Fill_DB_TAB(ByVal QueryString As String, ByVal DataBase As      
String, ByVal dt_Import As DataTable) As Boolean
    Dim objCommandBuilder As OleDbCommandBuilder
    ' Dim result As Boolean = True
    mCmd.Connection = GetConnection(DataBase)
    mCmd.Connection.Close()
    mCmd.Connection.Open()

    Dim DataSet As DataSet = New DataSet

    Try
        ' Run the query and create a DataSet.
        Dim mMainDbAdapter = New OleDbDataAdapter(QueryString, mCmd.Connection)
        mMainDbAdapter.Fill(DataSet)
        objCommandBuilder = New OleDbCommandBuilder(mMainDbAdapter)
        mMainDbAdapter.Update(dt_Import)                           ' Alle neu ('Added') in die DataTable aufgenommenen Sätze schreiben
        mMainDbAdapter.Dispose()
        mMainDbAdapter = Nothing
        objCommandBuilder.Dispose()


    Catch ex As Exception
        'result = False
        Extras.write_in_Logfile(ex.Message)
        Main.gResult = False
        System.Diagnostics.Debug.WriteLine(ex.Message, MsgBoxStyle.Critical, "Verbindungsfehler")
    Finally
        ' Close the database connection if it is still open.
        mCmd.Connection.Close()
    End Try
    Return Main.gResult
End Function

问题已解决,抱歉浪费您的时间。说明在评论中

4

0 回答 0