110,533
社区成员
发帖
与我相关
我的任务
分享
//获取到csv文件名
string connectstr = e_fullfilepath.Substring(0, e_fullfilepath.Length - 13);
dbcon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connectstr + ";Extended Properties='Text;FMT=Delimited;HDR=NO'; ");
// dbcon = new OdbcConnection("Driver={Misrosoft Text Driver(*.txt;*.csv)}; Dbq=" + odbcfilepath_replace + "; Extensions=asc,csv,tab,txt:Persist Security Info=False");
dbcon.Open();
try
{
if (dbcon.State == ConnectionState.Closed)
{
dbcon.Open();
}
//获取文件名,获取后12位字符,文件名格式必须确定
string dtname = e_fullfilepath.Substring(e_fullfilepath.Length - 12);
OleDbCommand cmd = new OleDbCommand("select * from [" + dtname + "]", dbcon);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
DataSet dstable = new DataSet();
//文件数据放入一个datatable 代码
adapter.Fill(dstable,"csv");