Can you please show what work you may have already undertaken on this particular project? The code you're asking for is not really that "easy" to show, and it is heavily dependant upon the format of your spreadsheet, as well as the database schema you want to import into.
I suggest looking into ADO.NET's OleDB data model for loading to and from SQL and the Excel, and then look at SQL Management Objects (SMO) for creating the appropriate tables in your database.
But as an aside, why not use a tool that is good at doing this, like Business Intelligence Development Studio? You can program an SSIS package to run via C#.
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
Thanks for your reply ....My project is a web - based application using ASP.NET and C# and it requires that the user should be able to import the excel data into the database ....becoz there are situations when the user has already the information stored in excel and he doesn't want to add the record again that's why my applications requires import option for importing ........ Actually I want to import all the fields of the excel into the two tables...but both table has many fields and there are only 5 columns which I need to export in those two tables and both tables has 10 fields and I need to export only 5 fields from the excel ....
...So what part are you having issues with? Do you not know how to use ADO.Net to read Excel, or write to a SQL server? We can't provide full-fledged code solutions like this-- it is fairly involved, like I mentioned.
Here are some Google searches that might help you out:
Reading Excel from C#: http://www.google.com/search?q=C%23+read+Excel+file
Writing data to SQL server in C#:
http://www.google.com/search?q=insert+rows+SQL+C%23
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147