Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Refreshing a DataSet
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00702106
Message ID:
00702360
Views:
19
No, we're not using the DataAdapter for updates, only for filling DataSets. For updates, we just use SqlCommand.ExecuteNonQuery().

~~Bonnie


>Are you even using the DataAdapter? This approach was the different ways to use the Update method of a DataAdapter. There are many different ways to perform updates in general.
>
>>Hmmmm .... interesting. Thanks Cathi ... it's not the way we're doing it, but no one says we're doing it the right way. <g> I guess there's more than one way to skin a cat ... it's nice to have several options.
>>
>>~~Bonnie
>>
>>
>>
>>>Hi Eric and Bonnie,
>>>
>>>You can update/add/delete DataRows using two approaches, either by writing your own statements or using stored procedures. One misconception in ADO.NET is that updates are batch processed. In actuality, each row is being sent separately to the backend when you call the DataAdapter's Update method.
>>>
>>>If your backend database supports batch queries (like SQL Server), then you can return from either a command statement or from a stored procedure, your updated row information. For a command statement, just append a SELECT statement to the end of your command statement, separating the two statements with a ";". Here is an example of an INSERT statement:
>>>
>>>
>>>MySqlInsertCommand.CommandText =
>>  "INSERT INTO Employees(LastName, FirstName)
>>   VALUES (@LastName, @FirstName);
>>
>>   SELECT EmployeeID, LastName, FirstName FROM Employees
>>    WHERE (EmployeeID = @@IDENTITY)"
>>>
>>>
>>>For a Stored Procedure, you can use the following comparable code, still adding a Select statement:
>>>
>>>
>>>ALTER PROCEDURE dbo.SPInsertCommand
>>>(
>>>	@LastName nvarchar(20),
>>>	@FirstName nvarchar(10)
>>>)
>>>AS
>>>	SET NOCOUNT OFF;
>>>INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName);
>>>	
>>>SELECT EmployeeID, LastName, FirstName FROM Employees
>>> WHERE (EmployeeID = @@IDENTITY)
>>>
>>>
>>>When you run this, the DataAdapter knows to look for the results from the InsertCommand and the UpdateCommand because of its UpdatedRowSource property. This property accepts a value from the UpdateRowSource enumeration. By default, the Command will fetch new data from the modified row by checking for output parameters and the first row returned by the query.
>>>
>>>The DataSet will contain the updated information. Hope this helps.
>>>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform