updating vs. inserting

T

Tina

Below is pasted how I normally do an insert using a design time data adapter
and dataset in an

ASP.NET application. How can I least modify this code to do an update? (I
have all of the commands

generated in the data adapter)
Thanks,
T

Dim insertRow As dsPartNumsNew.PartNumbersRow
insertRow = DsPartNumsNew1.PartNumbers.NewRow()
insertRow.PP_Part_Num = tbPartNo.Text
insertRow.Description = tbDescription.Text
insertRow.Category = tbCategory.Text
insertRow.Manufacturer = tbManufacturer.Text
If tbPrice.Text.Trim = "" Then
insertRow._Price_ = 0
Else
insertRow._Price_ = tbPrice.Text
End If
insertRow.GL_Code = ddlGL.SelectedValue
insertRow.DeletedByUser = False
insertRow.TrackInventory = cbTrackInv.Checked
'add the row to the dataset...
Try
DsPartNumsNew1.PartNumbers.AddPartNumbersRow(insertRow)
daPartNumsNew.Update(DsPartNumsNew1)
Catch ex As SqlException
If ex.Number = 2627 Then
lblError.Text = "Part already exists"
Exit Sub
Else
lblError.Text = ex.Message
Exit Sub
End If
End Try
 
W

W.G. Ryan eMVP

If you have all of the commands, the rowstate is always going to be added
and your update command is going to fire here.
 
T

Tina

Sorry, but I've read your answer several times and I don't understand what
you are saying.
T
 
T

Tina

On second thought, maybe you are saying that if the row already exists, my
Update
command would fire instead of my insert command? If so, that is not
happening
because I get the 2627 dup exception.
T
 

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