Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC Excel databse
Hi friends,
 
I want to read a data from excel and need to validate that and insert into sql server database using MVC alone.
I googled a lot for the thing and nothing works for me, SAD MAN.
Any links or tips are greatly appreciated.
 
Thanks in advance.
Posted 9-Oct-12 22:36pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

After finding Linq to excel I felt relax,
I use LinqtoExcel library to read data from the excel sheet.
imported linqtoexcel.dll into my application and use this statement in the controller,
 
var excel = new ExcelQueryFactory("C:\\Documents and Settings\\rk.prabakar\\Desktop\\test.xlsx");
           var dataContent = from c in excel.Worksheet<CheckingAccount>()
                             select c;
Here the data are retrieved from the excel sheet and stored in datacontent variable.
//Checking the datacontent before accessing
if (dataContent != null)
 
            {
//reading content from the excel comes here
                foreach (var a in dataContent)
                {
                    userId = Convert.ToInt16(Session["UserId"]);
//a.AccountName is the header row in the excel sheet, which is assigned to accountname variable.                    
                    accountName = a.AccountName;
                    acctDate = a.AccountOpenDate;
                    currBal = a.CurrentBalance;
                    //_checkingaccountService.CreateCheckingAccountID(userId, accountName, acctDate, currBal);
//Calling the function from the checking transaction by passing the values.
                    _checkingtransactionservice.CreateCheckingTransaction(userId, accountName, acctDate, currBal);
                    currBal.InjectFrom(impfile);
                    //    i++;
                }
Finally I got it.
  Permalink  
Comments
Vishal Pand3y at 20-May-14 13:22pm
   
good at least after solving your problem you post it
very helpful Thanks :)

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



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100