我在.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驱动程序管理器]未找到数据源名称且未指定默认驱动程序
我做错了什么?
答案 0 :(得分:1)
您不需要转义VB.NET字符串中的\字符,因此“Dbq = D:\\ csv”应为“Dbq = D:\ csv”。这就是找不到您的数据源的原因。