我不知道这里的strConn语句有没有问题,我也不清楚到底怎么写!请那位高手指点指点!只要到conn.Open();就会出现异常,我估计是连接字符串有问题!我等着完成这个任务!
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Driver={Microsoft.Text.Driver (*.csv)}; Data Source = " + Path + ";" + "Extensions Properties=csv;FMT=TabDelimited;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string strExcel = "";
OleDbDataAdapter myCommand = null;
if (Table == "shareit")
strExcel = "SELECT * FROM [" + dt.Rows[0]["TABLE_NAME"].ToString() + "] WHERE EMAIL<>null";
else
if (Table == "paypal")
strExcel = "SELECT * FROM [" + dt.Rows[0]["TABLE_NAME"].ToString() + "] where [ From Email Address] <> null";
DataSet ds = new DataSet();
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, Table);
conn.Close();
return ds;
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Driver={Microsoft.Text.Driver (*.csv)}; Data Source = " + Path + ";" + "Extensions Properties=csv;FMT=TabDelimited;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string strExcel = "";
OleDbDataAdapter myCommand = null;
if (Table == "shareit")
strExcel = "SELECT * FROM [" + dt.Rows[0]["TABLE_NAME"].ToString() + "] WHERE EMAIL<>null";
else
if (Table == "paypal")
strExcel = "SELECT * FROM [" + dt.Rows[0]["TABLE_NAME"].ToString() + "] where [ From Email Address] <> null";
DataSet ds = new DataSet();
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, Table);
conn.Close();
return ds;
解决方案 »
- asp,net实现图片上传到数据库的问题,在线等
- FckEditor编辑器在使用时有'就会报错
- 有關於判斷字節流的長度.............................
- 求一个思路,有没有可能在ASP.NET的datagrid当中,实现某一列多个cell合并?
- C# UDP接收 如何获取源数据的IP?
- 关于记录从其它网站链接到来网站的URL,大家都如何解决,有什么方法可以解决?Request?
- 求解MVC3的问题,
- 为什么不能读Request.QueryString["TextBox"]?
- .net通过cache.insert缓存后,后续的操作影响缓存的数据
- win10新机安装了VS2017后,创建MVC项目有错误
- gridview更新记录问题,在线等!急!
- 控件问题!!请高手帮忙!!
public DataSet GetDataSetFromCSV(string filePath, string fileName)
{
string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=";
strConn += filePath; //filePath, For example: C:\
strConn += ";Extensions=asc,csv,tab,txt;" ;
OdbcConnection objConn = new OdbcConnection(strConn);
DataSet dsCSV = new DataSet();
try
{
string strSql = "select * from " + fileName; //fileName, For example: 1.csv
OdbcDataAdapter odbcCSVDataAdapter = new OdbcDataAdapter(strSql, objConn);
odbcCSVDataAdapter.Fill(dsCSV);
return dsCSV;
}
catch(Exception ex)
{
throw ex;
}
}
http://www.cnblogs.com/chenyunfan/articles/599482.html
string strSql = "select * from " + fileName;这里的fileName中包含有路径(只能是文件名)
而上面的strConn += filePath的filePath只能用路径,关于这一点myminimouse(坚决不用baidu)已说得很清楚了