[英]CSV upload in .NET using ODBC
Hi i have CSV upload code in .net 嗨,我在.net中有CSV上传代码
In C# 在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();
}
}
In .VB 在.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()
In C# is working fine But in .VB its giving error when filling the dataset .- 在C#中工作正常,但在.VB中,填充数据集.-时出现错误
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 错误[IM002] [Microsoft] [ODBC驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序
what I am doing wrong? 我做错了什么?
You don't need to escape the \\ character in VB.NET strings so "Dbq=D:\\\\csv" should be "Dbq=D:\\csv". 您不需要在VB.NET字符串中转义\\字符,因此“ Dbq = D:\\\\ csv”应为“ Dbq = D:\\ csv”。 That's why your data source isn't found.
这就是为什么找不到您的数据源的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.