Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

duplicating inserts

Status
Not open for further replies.

michelleHEC

Programmer
Oct 20, 2003
95
US
why would an insert duplicate itself on occasion?
 
If you don't .AcceptChanges() on your datasource, perhaps?
 
could you explain further? I am building a dataadapter and using this code to insert... I am not using a dataset.
(I open and close it also)

daInsertFinal.InsertCommand.Parameters.Item("@LastID").Value = rdrFinal.Item("name")
daInsertFinal.InsertCommand.ExecuteNonQuery()

Thank you for your quick response.
 
If you're using a DataAdapter and DataSet/DataTable, you don't want to set and execute your codes manually from code. You want to prepare your commands, or use the CommandBuilder, and then call the .Update method of your DataAdapter.
 

ok, I think I understand what you are saying, I am not sure how to do it though. I am going to try to figure it out though. Thank you so much for your input. I might have more questions later!
 
Is this what you are talking about?
daInsert.Fill(ds)
Dim t As DataTable
t = ds.Tables("tmpdailycrewtest")
Dim myrow As DataRow
myrow = t.NewRow()

myrow("Name") = lblName(intC).Text
myrow("EmpNo") = lblNumber(intC).Text
myrow("AccountNo") = lblAccountNew(intC, intN).Text
myrow("JobNo") = lblJobNew(intC, intN).Text
myrow("TruckNo") = strTruckNO.PadLeft(3, "0") 'cboTruck(intC, intN).Text
myrow("TruckHrs") = txtTruckHours(intC, intN).Text 'this is for vehicle hours
myrow("TrailerNo") = strTrailerNO 'cboTrailer(intC, intN).Text
myrow("TrailerHrs") = txtTrailerHours(intC, intN).Text 'this is for vehicle hours
myrow("TrenchNo") = strTrenchNO 'cboTrench(intC, intN).Text
myrow("TrenchHrs") = txtTrenchHours(intC, intN).Text 'this is for vehicle hours
myrow("EarnType") = lblEarnTypeNew(intC, intN).Text
myrow("Hours") = txtHoursNew(intC, intN).Text
myrow("Notes") = txtNotes.Text
myrow("TimeCardDate") = lblDate.Text
myrow("Foreman") = lblForeman.Text
myrow("Passenger") = strPassenger
t.Rows.Add(myrow)
Dim pdsIR As DataSet
pdsIR = ds.GetChanges(DataRowState.Added)
If Not pdsIR Is Nothing Then
Me.daInsert.Update(pdsIR)
End If
ds.AcceptChanges()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top