日期:2014-05-17 浏览次数:21148 次
private void button1_Click(object sender, EventArgs e)
{
subImportCsv_Dataset("C:\\data\\", "AHU1_数据记录0.csv");
}
public void subImportCsv_Dataset(string filePath, string fileName)
{
string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=";
strConn += filePath;//这个地方只需要目录就可以了
strConn += ";Extensions=asc,csv,tab,txt;";
OdbcConnection objConn = new OdbcConnection(strConn);
try
{
string strSQL = "select * from " + fileName;//文件名,不要带目录
OdbcDataAdapter da = new OdbcDataAdapter(strSQL, objConn);
DataSet ds = new DataSet();
da.Fill(ds);
}
catch (Exception ex)
{
throw ex;
}
}