主题:问个关于C#读取CSV文件时代码的问题
string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};" +
"Dbq=C:;Extensions=csv,txt";
try
{
OdbcConnection objCSV = new OdbcConnection(strConn);
objCSV.Open();
OdbcCommand oCmd = new OdbcCommand("select column1,column2 " +
"from THECSVFILE.CSV", objCSV);
OdbcDataReader oDR = oCmd.ExecuteReader();
while (oDR.read())
{
// Do something
}
oDR.Close();
oCmd.Dispose();
objCSV.Close();
}
catch {}
这段代码中,跑到OdbcDataReader oDR = oCmd.ExecuteReader();这里就会抛出异常,原因不明,还请高人指教。还有就是C#里设置读取文件路径的字符传,正常按照路径写老是报错为什么呢?
"Dbq=C:;Extensions=csv,txt";
try
{
OdbcConnection objCSV = new OdbcConnection(strConn);
objCSV.Open();
OdbcCommand oCmd = new OdbcCommand("select column1,column2 " +
"from THECSVFILE.CSV", objCSV);
OdbcDataReader oDR = oCmd.ExecuteReader();
while (oDR.read())
{
// Do something
}
oDR.Close();
oCmd.Dispose();
objCSV.Close();
}
catch {}
这段代码中,跑到OdbcDataReader oDR = oCmd.ExecuteReader();这里就会抛出异常,原因不明,还请高人指教。还有就是C#里设置读取文件路径的字符传,正常按照路径写老是报错为什么呢?