0

我的代码工作得很好,但是当我生成 CSV 文件的新更新版本时,它突然对我出错并给我一个类型不匹配的捕获。

这是我现在拥有的代码。

 Dim A As String = "ADusers.csv"
    Dim B As String = "MlnExp.csv"
    Dim filePath As String = "C:\CSV"

    Try
        Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & (filePath) & "\;Extended Properties='text;HDR=Yes'"

        Dim sSql As String = "SELECT *" _
        & "FROM ([" & (B) & "] B LEFT JOIN [" & (A) & "] A ON B.EmployeeNumber = A.employeeID)"

        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConnectionString)
        Dim Command As OleDb.OleDbCommand = New OleDb.OleDbCommand(sSql, conn)
        Command.CommandType = CommandType.Text
        conn.Open()

        Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sSql, conn)
        Dim dt As DataTable = New DataTable
        da.Fill(dt)

        DataGrid1.DataSource = dt
        DataGrid1.Update()

        conn.Close()
        lblStatus.Text = "CSV combined... Now saving to file."


    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Exclamation)


    End Try

在它通过之前,合并两个 CSV 文件,然后将它们显示在我的数据网格中。但现在我的捕获物被扔了回来

表达式中的类型不匹配

4

1 回答 1

0

我会在您的两个文件中检查 B.EmployeeNumber = A.employeeID 一个是文本值(左对齐),另一个是 aa 整数(右对齐)

于 2013-10-22T19:22:55.903 回答