Click here to Skip to main content
14,695,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am developing a finance application in that i have a requirement of inserting a data from DataGridView to the Database. The DataGridview is filled from Excel file. Now i want to create a database from coding and wants to create a table and then store the data into that table.
Posted
Comments
David_Wimbley 18-Jan-13 1:16am
   
Is this database SQL Server? If so you can manipulate the database using Sql Server Management Objects or you can use just plain ADO.net and SQL Scripts (Create Table...Create Database...etc.). If you clarify ill post some samples.
Rockstar_ 18-Jan-13 1:28am
   
i clarified, but the thing is the user of this application doesn't have technical knowledge so he/she will select the excel file and just click on a button, then all the data from excel file should go to the database.

Hi,

I have a similar application.

What I did was to create the necessary tables in my database.
Then have a paste button for the user to paste excel copied data to grid.
Then a save button to save to the database.

The save button runs a stored procedure accepting all the required grid columns as parameters and inserts to db. All parameters are varchar and any conversion done on the SQL side within the SP.

Hope this helps.
   
If you want all the data from the excel file to go to a database dynamically the best way to be about this business is use Entity Framework Codefirst.

You can store your data in some List objects. Then you can enumerate through the list and you can insert the data in the data context object using a model object. When you save the changes to the DbContext object then entity framework will create a data for you in the background and you don't have to worry about a thing.

There are some great tutorials on Entity Framework Codefirst in:

1. pluralsight.com
2.An article in codeguru[^]
3. An article in codeplex[^]
4. An article by Scott Guthrie[^]

The last 2 are web based, but you will find conceptual explanation in the first two.
   
v2

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