如何将数据集中的记录插入数据库 [英] How do I insert records from dataset into database

查看:65
本文介绍了如何将数据集中的记录插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows表单。



我已经过滤了我的数据集中的记录,我需要将其复制到我的数据库的本地副本,但需要一个示例如何去做这个。当地的数据库已经建成。我试图遍历数据集中每个表中的列并插入。这就是我到目前为止。



I am using Windows forms.

I have filtered records in my dataset that I need to copy to a local copy of my database but need an example of how to do this. The local databse is already built. I am trying to loop through the columns in each table in the dataset and insert. This is what I have so far.

try
            {
               foreach (DataColumn c in ds.Tables[0].Columns)
               {
                 string strSQL = "Select * from " + dsTables.Tables[0];
                 SqlCeDataAdapter daCe = new SqlCeDataAdapter(strSQL, strCEConnection);
                 SqlCommandBuilder daCEcmd = new SqlCommandBuilder(daCe);
               }
            }
            catch
            { }
            finally { }

推荐答案

请阅读以下文章:

如何使用Visual C#2005或Visual C#.NET从DataSet对象更新数据库 [ ^ ]

如何将数据从DataSet保存到T-SQL表中 [ ^ ]

使用SqlDependency和SqlCach 查询通知eDependency [ ^ ]

使用SqlDependency进行数据更改事件 [ ^ ]
Please, read the following articles:
How to update a database from a DataSet object by using Visual C# 2005 or Visual C# .NET[^]
How to save data from a DataSet into a T-SQL table[^]
Query Notification using SqlDependency and SqlCacheDependency[^]
Using SqlDependency for data change events[^]


我使用数据适配器来构建插入命令。我用映射到我的数据库表的模式填充了一个数据集。然后循环遍历每行中的列,添加行并调用update命令来填充数据库表。
I used a data adapter to build the insert command. I filled a dataset with the schema mapped to my database table(s). Then looped through the columns in each row, added the rows and called the update command to fill the database table.


这篇关于如何将数据集中的记录插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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