下面有详细方法:
http://www.connectionstrings.com/default.aspx
导入的文件下必须有一个命名为"Schema.ini"的配置文件,如何配置,上面的网址里有详细说明.
如下示例:
http://www.connectionstrings.com/default.aspx
导入的文件下必须有一个命名为"Schema.ini"的配置文件,如何配置,上面的网址里有详细说明.
如下示例:
string dir=Path.GetDirectoryName(filePath);
string filename=Path.GetFileName(filePath);
string conStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\\;Extended Properties=\"text;HDR=Yes;FMT=Delimited(,)\";", dir);
using (OleDbConnection oledbCon = new OleDbConnection(conStr))
{
OleDbDataReader reader=null;
OleDbCommand oledbCom = new OleDbCommand();
oledbCom.Connection = oledbCon;
oledbCom.CommandText = string.Format("select top 1 * from {0}", filename);
try
{
oledbCon.Open();
reader = oledbCom.ExecuteReader(); }
catch (SqlException e)
{
throw new Exception(e.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
}
string filename=Path.GetFileName(filePath);
string conStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\\;Extended Properties=\"text;HDR=Yes;FMT=Delimited(,)\";", dir);
using (OleDbConnection oledbCon = new OleDbConnection(conStr))
{
OleDbDataReader reader=null;
OleDbCommand oledbCom = new OleDbCommand();
oledbCom.Connection = oledbCon;
oledbCom.CommandText = string.Format("select top 1 * from {0}", filename);
try
{
oledbCon.Open();
reader = oledbCom.ExecuteReader(); }
catch (SqlException e)
{
throw new Exception(e.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
}