Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to import excel data to sql server but data only read not save to sql server what im missing
thank for help
here my code

C#
List<MASTER_ITEM> lsMaster_item = new List<MASTER_ITEM>();
if (FileUpload1.HasFile && Path.GetExtension(FileUpload1.FileName) == ".xlsx")
{
    using (var excel = new
        ExcelPackage(FileUpload1.PostedFile.InputStream))
    {
        var worksheet = excel.Workbook.Worksheets.First();
        for (int row = 2; row <= worksheet.Dimension.End.Row; row++)
        {
            var ITEM_ID = worksheet.Cells[row, 1].Value;//คอลัมน์ 1
            var ITEM_NO = worksheet.Cells[row, 2].Value;
            var ITEM_NAME = worksheet.Cells[row, 3].Value;

               lsMaster_item.Add(new MASTER_ITEM
            {
                ITEM_ID = item_ID_convert,
                ITEM_NO = ITEM_NO == null ? "" : ITEM_NO.ToString(),
                ITEM_Name = ITEM_NAME == null ? "" : ITEM_NAME.ToString()
             });
                    GridView1.DataSource = lsMaster_item.ToList();
                GridView1.DataBind();
                   }
Posted
Comments
Member 11428137 11-Mar-15 22:22pm    
It looks like you may be using Entity Framework, as you are loading your data into typed objects, but you haven't shown any code for saving them. You need to attach them to your context, and then call SaveChanges() on the context.
Member 11363027 11-Mar-15 22:56pm    
how i really new to this
Subramanyam Shankar 13-Mar-15 11:48am    
where is the code to save into database?
Member 11363027 14-Mar-15 3:42am    
no have the data show only gridview but thats is my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900