Home All Groups Group Topic Archive Search About

Problem adding new row in Access Table

Author
8 Feb 2006 10:15 AM
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).

Author
8 Feb 2006 11:48 AM
Ken Tucker [MVP]
Hi,

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

Ken
---------------------
Show quoteHide quote
"RPK" <R**@discussions.microsoft.com> wrote in message
news:4DB26F5B-4ECB-4D45-8307-3C5D02454BDC@microsoft.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).
Author
8 Feb 2006 12:35 PM
RPK
Ken,

Please illustrate the lines where the changes are needed.

Thanks.

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

Show quoteHide quote
"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" <R**@discussions.microsoft.com> wrote in message
> news:4DB26F5B-4ECB-4D45-8307-3C5D02454BDC@microsoft.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).
>
>
>
Author
9 Feb 2006 1:24 AM
Ken Tucker [MVP]
Hi,

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

        'Commit Changes
        TempDS.AcceptChanges()

Ken
----------------
Show quoteHide quote
"RPK" <R**@discussions.microsoft.com> wrote in message
news:1A3800C2-8815-45DD-89A4-57F1F5B2B308@microsoft.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" <R**@discussions.microsoft.com> wrote in message
>> news:4DB26F5B-4ECB-4D45-8307-3C5D02454BDC@microsoft.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).
>>
>>
>>