在sql中创建数据库并动态地将数据插入数据库 [英] Create database in sql and insert the data into the databse dynamically

查看:91
本文介绍了在sql中创建数据库并动态地将数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,



我正在开发一个财务应用程序,因为我需要从DataGridView向数据库插入数据。 DataGridview是从Excel文件填充的。现在我想从编码创建一个数据库,并希望创建一个表,然后将数据存储到该表中。

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.

推荐答案





我有类似的申请。



我所做的是在我的数据库中创建必要的表格。

然后有一个粘贴按钮,供用户将excel复制数据粘贴到网格。

然后是一个保存按钮保存到数据库。



保存按钮运行存储过程,接受所有必需的网格列作为参数并插入到db。所有参数都是varchar,并且在SP内的SQL端进行任何转换。



希望这会有所帮助。
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.


如果你想要来自excel文件的所有数据动态地转到数据库,关于这个业务的最佳方式是使用Entity Framework Codefirst。



您可以将数据存储在某些List对象中。然后,您可以枚举列表,并可以使用模型对象将数据插入数据上下文对象中。当您将更改保存到DbContext对象时,实体框架将在后台为您创建数据,您不必担心任何事情。



有关Entity Framework Codefirst的一些很棒的教程:



1. pluralsight.com

2. codeguru中的一篇文章 [ ^ ]

3. Codeplex中的一篇文章 [ ^ ]

4. Scott Guthrie的一篇文章 [ ^ ]



最后2个是基于网络的,但你会在前两个中找到概念性解释。
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.


这篇关于在sql中创建数据库并动态地将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆