Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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 { }
Posted
Updated 4-Apr-13 5:26am
v2
Comments
Richard C Bishop 4-Apr-13 11:48am    
You will need to do an update or insert statement if you are trying to add items to a database.

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.
 
Share this answer
 
Comments
Maciej Los 4-Apr-13 17:39pm    
So, you did exactly as is described in the first linked article...

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