views:

1014

answers:

1

hi,

I am a newbie to Database programming. After inserting a couple of rows into a DataSet object, I am trying to write back the updated DataSet to the Database but cannot figure out how to do it.

Can you give an example for the following please?

  • what SQL insert command to use if DataSet is already updated with new rows
  • Databinding example - especially considering an initially empty table in the DB

I am using SQLExpress 2008 & its C# WinForms application.

thanks

ps: I have already looked at the related questions here. This one is different in that I am first adding my new data into a DataSet and want to update the DB then.

+3  A: 

What you need to do is configure a DataAdapter or TableAdapter object that contains the proper Update command. Then when you are done updating the rows in your DataSet, you can call DataAdapter.Update(DataSet) and it will do all the hard work for you.

Since you're starting out, I'd suggest looking at the TableAdapter objects that are built using the XSD schema tool. They allow you to simply drop your tables into the XSD to create a schema, and then let the wizard generate the appropriate SQL commands (it'll even do Stored Procedures for you) to handle all the CRUD work. I've been using these for a while and love them.

EDIT: In response to Sesh's request, Scott Gu has a great tutorial series on using the Table Adapters here. I wanted to post this in the answer so others can find it easily.

Dillie-O
hi, can you point me to an example for this? thanks.
Sesh