嗨,我在 .net 中有 CSV 上传代码
在 C# 中
string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=D:\\csv;Extensions=asc,csv,tab,txt;Persist Security Info=False";
DataSet ds;
using (OdbcConnection oConn = new OdbcConnection(strConnString))
{
using (OdbcCommand oCmd = new OdbcCommand())
{
oCmd.Connection = oConn;
oCmd.CommandType = System.Data.CommandType.Text;
oCmd.CommandText = "select * from [my.csv]";
OdbcDataAdapter oAdap = new OdbcDataAdapter();
oAdap.SelectCommand = oCmd;
ds = new DataSet();
oAdap.Fill(ds, "my");
oAdap.Dispose();
ds.Dispose();
}
}
在.VB中
Dim strConnString As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=D:\\csv;Extensions=asc,csv,tab,txt;Persist Security Info=False"
Dim lOdbcConnection As New OdbcConnection(strConnString)
' lOdbcConnection.ConnectionString = strConnString
'lOdbcConnection.Open()
Using lOdbcCommand As New OdbcCommand, lOdbcDataAdapter As New OdbcDataAdapter
lOdbcCommand.Connection = lOdbcConnection
lOdbcCommand.CommandType = System.Data.CommandType.Text
lOdbcCommand.CommandText = "select * from [my.csv]"
lOdbcDataAdapter.SelectCommand = lOdbcCommand
Dim ds As New DataSet()
lOdbcDataAdapter.Fill(ds, "my")
ds.Dispose()
lOdbcDataAdapter.Dispose()
在 C# 中工作正常但在 .VB 中填充数据集时出现错误.-
错误 [IM002] [Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序
我做错了什么?