Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Add, Edit, Delete, Cancel Records
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00724368
Message ID:
00724877
Vues:
34
Thank you Cathi,

This was also helfull for me, I was stuck in there (missing the SqlCommandBuilder(sda)).

Only one doubt: I didn't understand the "SqlCommandBuilder & GetUpdateCommand" job, is it that, they will find what update method happened to the DataAdapter and will excute it in the database side?

Thanks again for the help.



>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
<><><><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><><><>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform