如何将数据集中的记录插入数据库

问题描述:

我正在使用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.