Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Add, Edit, Delete, Cancel Records
Message
 
To
20/11/2002 10:55:34
Rex Mahel
Realm Software, Llc
Ohio, United States
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00724368
Message ID:
00725276
Views:
13
Rex,

Yes, if an Update fails and you have a Try/Catch, the Catch will be triggered. Here is some info from the online help that explains this and how you can code around the exception:

If an error occurs while updating a row, an exception is thrown and execution of the update is discontinued. To continue the update operation without generating exceptions when an error is encountered, set the ContinueUpdateOnError property to true before calling Update. You may also respond to errors on a per-row basis within the RowUpdated event of the SqlDataAdapter or OleDbDataAdapter. To continue the update operation without generating an exception within the RowUpdated event, set the Status property of the RowUpdatedEventArgs to Continue.

>Cathi,
>
>PMFJI, but I have a question. If you place the Update command within a Try Block and the Update failed, would this trigger the Catch clause? If that is the case, you probably would not have to check for the return value from the Update, just run the RejectChanges() in the Catch clauses.
>
>Thanks
>
>Rex
>
>>Here is some sample code that I am using this week for my ADO.NET session at Whilfest. It should answer your questions about how work with your data.
>>
>>Steps involved:
>>Modify data inside of DataSet as necessary
>>Call Update method of DataAdapter
>>Call the AcceptChanges method of the DataSet
>>
>>Updating Data:
>>
>>
>>Dim strSQL As String = "SELECT * FROM Authors “ & _
>>	“Where au_lname='Green'"
>>Dim sda As New SqlDataAdapter(strSQL, connStr)
>>Dim scb As New SqlCommandBuilder(sda)
>>sda.UpdateCommand = scb.GetUpdateCommand()
>>Dim ds As New DataSet()
>>Dim dr As DataRow
>>
>>sda.Fill(ds, "AuthorInfo")
>>dr = ds.Tables("AuthorInfo").Rows(0)
>>dr("au_fname") = "Lisa"
>>
>>If sda.Update(ds, "AuthorInfo") = 1 Then
>>	ds.AcceptChanges()
>>Else
>>	ds.RejectChanges()
>>End If
>>
>>
>>Adding New Data:
>>
>>
>>Dim ds As New DataSet(), dr As DataRow, dt As DataTable
>>strSQL = "SELECT * FROM Authors Where 0=1"
>>Dim sda As New SqlDataAdapter(strSQL, cnn)
>>Dim scb As New SqlCommandBuilder(sda)
>>sda.InsertCommand = scb.GetInsertCommand()
>>
>>sda.Fill(ds, "AuthorInfo")
>>dt = ds.Tables("AuthorInfo")
>>dr = dt.NewRow()
>>dr("au_id") = "111-11-1111": dr("au_lname") = "Randell"
>>dr("au_fname") = "Brian": dr("contract") = 0
>>dt.Rows.Add(dr)
>>If sda.Update(ds, "AuthorInfo") = 1 Then
>>  ds.AcceptChanges()
>>Else
>>  ds.RejectChanges()
>>End If
>>
>>
>>>Hi,
>>>
>>>I created a simple project using windowform and vb.net.
>>>
>>>Standard Wizards.
>>>
>>>SqlConnection, SqlDataAdapter1 (Employees), SqlDataAdapter2 (JobType), SqlDataAdapter3 (JobTitle) and a DataSet with all 3 tables included in the generate dataset wizards.
>>>
>>>Added SearchLastName(Textbox), SearchButton, DataGrid1 to display the results of the search and textboxes, Comboboxes and 5 buttons to the Form for the edits etc. for the detail fields.
>>>
>>>The idea here is to:
>>>
>>>(1) Type in the lastname and click search, Position the grid to the desired record and click the EDIT BUTTON to edit the textboxes/comboboxes (fields) and then CLICK BUTTON to update (save) changes to the record and to the datasource; Optionaly you can click the CANCEL BUTTON and that would undo the changes that you made to the textboxes etc.
>>>
>>>(2) Position the grid to the desired record and click the DELETE BUTTON the selected record.
>>>
>>>(3) Click the ADD BUTTON to add a new Record and SAVE BUTTON would add it to the datasource. Also the CANCEL BUTTON would allow to cancel the add record.
>>>
>>>What is the proper coding for SQL DataApater and Datasets when a button is clicked to:
>>>
>>>ADD a Record to the dataset for Employees table:
>>>
>>>EDIT/CHANGE selected record in the dataset for Employees table:
>>>
>>>SAVE Edits/Changes selected Record to the dataset for Employees table:
>>>
>>>DELETE selected record in the dataset from the Employees table:
>>>
>>>CANCEL Edits or Add to the dataset for the Employees table:
>>>
>>>
>>>Thanks
>>>Roland
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform