在VB中组合两个csv文件时键入不匹配

时间:2013-10-22 18:15:45

标签: sql vba csv datasource

我的代码运行得很好,但是当我生成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文件合并,然后在我的数据网格中显示它们。但现在我的抓住了回来

  

表达式中的类型不匹配

1 个答案:

答案 0 :(得分:0)

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