|
|
|
upload excel to sql จากพาท ทำไงดีครับ windows form |
|
|
|
|
|
|
|
บทความนี้เลยครับ
Code (C#)
FileInfo excel = new FileInfo(Server.MapPath(@"Xls/myData.xlsx"));
using (var package = new ExcelPackage(excel))
{
var workbook = package.Workbook;
//*** Sheet 1
var worksheet = workbook.Worksheets.First();
string strConnString = @"Server=localhost;UID=sa;PASSWORD=;database=mydatabase";
var objConn = new SqlConnection(strConnString);
objConn.Open();
//*** Loop to Insert
int totalRows = worksheet.Dimension.End.Row;
for (int i = 2; i <= totalRows; i++)
{
string strSQL = "INSERT INTO myTable (Column1,Column2,Column3,Column4,Column5) "
+ " VALUES ("
+ " '" + worksheet.Cells[i, 1].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 2].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 3].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 4].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 5].Text.ToString() + "' "
+ ")";
var objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
}
objConn.Close();
}
(C#) ASP.Net Excel & EPPlus Import Excel To Database
|
|
|
|
|
Date :
2017-09-27 09:29:45 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|