【急】用C#怎么把CSV文件导入到SQL中。

2024-12-04 06:45:35
推荐回答(1个)
回答(1):

/// 将csv格式文件导成dataset /// /// 文件路径 /// 文件名 /// public DataSet getCsv(string filePath, string fileName){string strConn = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="; strConn += filePath; strConn += ";Extensions=asc,csv,tab,txt;"; OdbcConnection con = new OdbcConnection(strConn); DataSet data = new DataSet(); string sql = "select * from " + fileName; OdbcDataAdapter adp = new OdbcDataAdapter(sql, con); con.Open();}然后你就插入数据库就可以了