Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

1 solution

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,

C#
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.
C#
//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.
 
Share this answer
 
Comments
Vishal Pand3y 20-May-14 13:22pm    
good at least after solving your problem you post it
very helpful Thanks :)
Member 11372755 23-Jan-15 14:50pm    
is there any way to get it from a input box

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