Datatable / Dataset Save

G

Greg

I have a Datatable/Dataset that I'd like to update back to the server. How do
I go about saving changes to my Datatable or Dataset back to the database?
 
G

Greg

Are there any examples, showing the whole process, from creating the
DataAdapter, DataSet/DataTable and then updating it?
 
L

Linda Liu[MSFT]

Hi Greg,

You can use DataAdapter to save changes in the DataSet/DataTable back to
the database. If you're using SQL Server, you can use SqlDataAdapter;
otherwise, you can use OleDbDataAdapter.

You can either make use of VS IDE to configure the SelectCommand,
UpdateCommand, InsertCommand and DeleteCommand of the DataAdapter, or
create the four commands in code by yourself. I suggest that you adopt the
first option for convenience.

After the commands of a DataAdapter are created, you can call the Update
method on the DataAdapter to save changes in the DataSet/DataTable to the
database.

For more information on how to configure a DataAdapter through Data Adapter
Configuration Wizard, please refer to the following document:
"How to: Create Data Adapters Using a Wizard"
http://msdn2.microsoft.com/en-us/library/zc6tc8ew(vs.80).aspx

For more information on how to create commands of a DataAdapter in code and
resolve changes to the database, please refer to the following document:
"Updating Data Sources with DataAdapters"
http://msdn2.microsoft.com/en-us/library/33y2221y(VS.80).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Greg

I know what I'm looking for is probably very unrealistic. I understand the
DataAdapter and all, but where I get lost is how I get to the UPDATE process.
I work best with examples, and it seems everything out there only shows a
very small portion of the solution and I'm not able to pull it all together.
Is there a sample somewhere out there that includes the whole soluction, form
creating a DataTable/DataSet to display data and then updating the data on a
form and saving it back to the database using the DataAdapter.

My problem is I have a BASE class that it is inhertited by my main class and
the DataAdapter has not specific name. it's used to create the DataTable, but
once I've created the DataTable, I work with it, display data, etc., but I
just don't know how to get back to the DataAdapter. I'm probably making no
sense, but I wish there was a solution/example that showed the whole thing
together. Then, I might be able to integrate it into what I already have.

Thanks for the help you have provided though. I'll just keep playing around
and hopefully soon I'll come up with an solution that works.

Sorry, I'm just frasted on how to get where I want to go.

Greg
 
C

Cor Ligthert[MVP]

Greg,

I did not see the commandbuilder in the messages. The DataAdapter needs
update SQL transactioncode.

AdoNet can make that for you (as long as it is about simple datatables).

Dim da as new SqlDataAdapter(connectionstring)

bla bla

dim cmb as new sqlCommandbuilder(da)

da.update(TheDataSet)

-
Cor
 
L

Linda Liu[MSFT]

Hi Greg,

Thank you for your prompt reply!
Is there a sample somewhere out there that includes the whole soluction,
form creating a DataTable/DataSet to display data and then updating the
data on a form and saving it back to the database using the DataAdapter.

I haven't found an existing sample you want so far, but it's not complex.
The main points of the application should be as follows:

1. Create a SqlConnection instance in code and initialize its
ConnectionString property.
2. Create a SqlDataAdapter instance in code.
3. Create four SqlCommand instances and set their CommandText property
respectively.
4. Assign the SqlConnection instance created above to the Connection
property of each SqlCommand instance.
5. Assign the four SqlCommand instances to the SelectCommand,
InsertCommand, UpdateCommand and DeleteCommand properties of the
SqlDataAdapter respectively.
6. Create a DataSet instance.
7. Call the SqlConnection.Open method to open the database connection.
8. Call the SqlDataAdapter.Fill method passing the DataSet instance to
fill the DataSet.
9. Bind the DataSet to controls on the form.
10. After the user makes some changes, call the SqlDataAdapter.Update
method to save the changes back to the database.

If you really need a sample that shows the whole solution, please feel free
to let me know and I will create a sample project for you.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Greg

I've come to really appreciate your responses and the information you provide
me. If its not too much trouble, could you create a sample project in VB.Net
2005? I'd really like ot see the whole solution and how its done. Then, from
there I can expand upon it.

Thanks so much.

Greg
 
L

Linda Liu[MSFT]

Hi Greg,

I have created a sample project that shows the whole solution for you and I
send it to your msn mailbox.

Before you run the sample application, please create a table in the
database. The table is named "Teacher" and contains four fields:

Column Name Data Type Allow Nulls
ID int no
Name varchar(50) yes
Age int yes
Address varchar(50) yes

If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top