.NETGURU
dataset to database not updating
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Paul Oliveira (VIP)
http://support.microsoft.com/default.aspx?scid=kb;EN-US;815660
on this online tutorial i have thi line that i do not understand...
--------------------------------------------------
To update the original database with all of these changes, pass the DataSet
into the Update method of the DataAdapter object.

However, before you can call Update, you must set the InsertCommand,
UpdateCommand, and DeleteCommand properties of the DataAdapter object. You
can manually write SQL and populate these three properties with corresponding
SqlCommand objects, but you can also use Visual Studio .NET to generate these
three commands automatically.

To generate the required commands when they are needed, you must create an
instance of the SqlCommandBuilder object and use the DataAdapter in the
constructor. If you want to use this method (shown in the code sample that
follows), you must have primary key information available for your table. To
access primary key information, call FillSchema, and then set the
MissingSchemaAction property of your DataAdapter to AddWithKey, or manually
set the primary key in your code.
--------------------------------------------

I open and created a data binding connection to the form controls using the
wizard and i works fine...

But i can not make the changes made into the dataSet to go also no the
database when i press the confirm button on the form.

I used the VS wizard to create the connection, but something must be missing?

How do i set the InsertCommand, UpdateCommand, and DeleteCommand properties
of the DataAdapter object?

Reply to this message...
 
    
Cowboy (Gregory A. Beamer) - MVP (VIP)
You either have to supply INSERT, UPDATE and DELETE commands or you can use
the CommandBuilder to create the INSERT, UPDATE and DELETE commands. THe
CommandBuilder is utilized by the DataAdapter for its work.

If you used the drag and drop methodology, you should already have these
created. Look at the "hidden code". If this does not help, try this on your
update method. You may have to tweak this code a bit as I am writing on the
fly:

C#
---
//Should already have code like so in the "hidden" area
SqlDataAdapter DataAdapter1 = new SqlDataAdapter(SqlCommand1);
....
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataAdapter1.UpdateCommand = cb.GetUpdateCommand();

VB.NET
---------
'Should already have code like so in the "hidden" area
Dim DataAdapter1 As new SqlDataAdapter(SqlCommand1)
....
'New code
Dim cb As New SqlCommandBuilder(DataAdapter1)
DataAdapter1.UpdateCommand = cb.GetUpdateCommand()

If you are using stored procedures, the CommandBuilder will not
automagically create the Update and you will have to link it yourself. Create
a stored procedure that accepts the fields from your DataSet and link to the
UpdateCommand of the DataAdapter. NOTE: I prefer this method regardless, as I
like more control of my control than the CommandBuilder affords.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Paul Oliveira" wrote:

[Original message clipped]

Reply to this message...
 
    
Paul Oliveira (VIP)
/* I´m working on VS.net in C++ */

My code has 3 private member that the wizard as created:
private: System::Data::SqlClient::SqlCommand * sqlSelectCommand1;
private: System::Data::SqlClient::SqlCommand * sqlInsertCommand1;
private: System::Data::SqlClient::SqlCommand * sqlUpdateCommand1;
private: System::Data::SqlClient::SqlCommand * sqlDeleteCommand1;

And I want to update the database when ok button is pressed:
private: System::Void buttonOk_Click(System::Object * sender,
System::EventArgs * e) {

this->sqlDataAdapter1->Update(dsClients1, "Clients");
}
I does not work, i dont now why...

About your replay:
when i write:
SqlCommandBuilder cb = new SqlCommandBuilder(da);
I generates a error, saying SqlCommandBuilter undeclared identifier.

"Cowboy (Gregory A. Beamer) - MVP" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Data.Common.DataAdapter
System.Data.DataSet
System.Data.MissingSchemaAction
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlCommandBuilder
System.Data.SqlClient.SqlDataAdapter
System.EventArgs




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification