Problem adding new row in Access Table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using following code to Add New Record in a Table (Temp in this case). I
want to save new record with this method i.e., non-SQL. It is not commiting
changes. The "Update" statement has errors.


'Initialize Data Adapter and Data Table Objects
TempDA.Fill(TempDS, "Temp")
TempDT = TempDS.Tables("Temp") 'Temp is the name of table


'Store to Temporary Table
'Start Connection
If Cn.State = ConnectionState.Closed Then
Call StartConnection()
End If

TempNewRow = TempDT.NewRow()
TempNewRow("Pno") = NewPNo
TempNewRow("PLName") = tab1_namepl

'Add the new row
TempDT.Rows.Add(TempNewRow)

'Commit Changes
TempDS.AcceptChanges()

dsChanges = TempDS.GetChanges
TempDA.Update(dsChanges, "Temp")

'Increment Permit Number
NewPNo = NewPNo + 1
Cn.Close()

If TempDS.HasChanges(DataRowState.Added) Then
MsgBox("Record successfully saved.", MsgBoxStyle.OKOnly,
"Success")
End If


Please also let me know which method for "Saving" record is fast (non-SQL).
 
Hi,

When you call TempDS.AcceptChanges it marks all the records as
unchanged. So dsChanges will not get any records.

Ken
 
Ken,

Please illustrate the lines where the changes are needed.

Thanks.
 
Hi,

dsChanges = TempDS.GetChanges
TempDA.Update(dsChanges, "Temp")

'Commit Changes
TempDS.AcceptChanges()

Ken
 

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

Back
Top