![](/img/trans.png)
[英]I am not able to read from Excel file and store into database using asp.net in c#?
[英]how to read from .csv file and store in database in asp.net using c#?
我正在上傳帶有數據的.csv文件..現在我必須從此.csv文件中讀取此數據並將其存儲在數據庫中...我已經使用excel完成了此操作,但是我無法在該項目中使用excel,因此我像這樣的excel代碼:
private bool writetoven()
{
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
try
{
OleDbCommand ocmd = new OleDbCommand("select * from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader odr = ocmd.ExecuteReader();
string vcode = "";
string pswd = "";
string vname = "";
while (odr.Read())
{
vcode = valid(odr, 0);
pswd = valid(odr, 1);
vname = valid(odr, 2);
insertdataintosql(vcode,pswd,vname);
}
excelConnection.Close();
return true;
}
catch (DataException)
{
return false;
}
finally
{
excelConnection.Close();
lblmsg4.Text = "Data Inserted Sucessfully";
}
}
沒有為.csv文件做些什么..我之前從未使用過.csv文件,因此需要對此的一些幫助
最簡單的方法是使用FileHelpers之類的庫http://filehelpers.sourceforge.net/
無需編寫所有細節和自己的代碼。 而且它非常快速和靈活。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.