By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,163 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,163 IT Pros & Developers. It's quick & easy.

Problem adding new row in Access Table

P: n/a
RPK
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).
Feb 8 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

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

Ken
---------------------
"RPK" <RP*@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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).

Feb 8 '06 #2

P: n/a
RPK
Ken,

Please illustrate the lines where the changes are needed.

Thanks.

----------------------------------------------------------------

"Ken Tucker [MVP]" wrote:
Hi,

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

Ken
---------------------
"RPK" <RP*@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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).


Feb 8 '06 #3

P: n/a
Hi,

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

'Commit Changes
TempDS.AcceptChanges()

Ken
----------------
"RPK" <RP*@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
Ken,

Please illustrate the lines where the changes are needed.

Thanks.

----------------------------------------------------------------

"Ken Tucker [MVP]" wrote:
Hi,

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

Ken
---------------------
"RPK" <RP*@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
>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).


Feb 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.