我試圖上傳csv文件並將數據保存到本地數據庫中。但是當我運行我的代碼時,它聲明'找不到可安裝的ISAM'。我不知道如何解決它。我已經研究過,大多數錯誤都與他們有關。但是我的代碼被突出顯示。找不到可安裝的ISAM(在'throw ex;'line)
我該如何解決?
我的代碼:
const string CSV_CONNECTIONSTRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"{0}\";Extended Properties=\"csv;HDR=YES;FMT=Delimited\"";
string csvPath = Server.MapPath("~/Files1/");
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Path.Combine(csvPath, fileName));
var AllFiles = new DirectoryInfo(csvPath).GetFiles("*csv");
string File_Name = string.Empty;
string ConString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
for (int i = 0; i < AllFiles.Length; i++)
{
try
{
File_Name = AllFiles[i].Name;
DataTable dt = new DataTable();
using (OleDbConnection con = new OleDbConnection(string.Format(CSV_CONNECTIONSTRING, csvPath)))
{
using (OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [Mcsv]", con))
{
da.Fill(dt);
}
}
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(ConString))
{
bulkCopy.ColumnMappings.Add(0, "medicine_id");
bulkCopy.ColumnMappings.Add(1, "category_id");
bulkCopy.ColumnMappings.Add(2, "subcategory_id");
bulkCopy.DestinationTableName = "medicine";
bulkCopy.BatchSize = dt.Rows.Count;
bulkCopy.WriteToServer(dt);
bulkCopy.Close();
}
}
catch (System.Exception ex)
{
throw ex;
}
證明是在錯誤 '扔恩;'
有很多不使用ado.net –
我仍然不明白CSV解析器.. – user8090359