AddNew concept with System.Data.OleDb 
Author Message
 AddNew concept with System.Data.OleDb

How do I add a new record like AddNew in the System.Data.OleDb.
Since there is an autonumber in the table I need this number to
generate other records in other tables.


Sat, 24 Apr 2004 02:53:09 GMT  
 AddNew concept with System.Data.OleDb
I had this problem in my project also. What I did to resolve this is to use

the autonumber of the record just added.

EC


Quote:
> How do I add a new record like AddNew in the System.Data.OleDb.
> Since there is an autonumber in the table I need this number to
> generate other records in other tables.



Sat, 24 Apr 2004 09:58:15 GMT  
 AddNew concept with System.Data.OleDb
Seeing as you're using oledb, as oppossed to the sql ones, I assume you're
not using sql server. You probably won't be able to use a statement like



Quote:
> I had this problem in my project also. What I did to resolve this is to
use

get
> the autonumber of the record just added.

> EC



> > How do I add a new record like AddNew in the System.Data.OleDb.
> > Since there is an autonumber in the table I need this number to
> > generate other records in other tables.



Sat, 24 Apr 2004 16:42:27 GMT  
 AddNew concept with System.Data.OleDb
I am using an access db.  I have used the AddNew in ADODB to retrieve
the last record but need the same for my .Net C# implementation.  I
would be Ideal if someone could point me in the right direction.

On Tue, 6 Nov 2001 08:42:27 -0000, "Martin Rogan"

Quote:

>Seeing as you're using oledb, as oppossed to the sql ones, I assume you're
>not using sql server. You probably won't be able to use a statement like



>> I had this problem in my project also. What I did to resolve this is to
>use

>get
>> the autonumber of the record just added.

>> EC



>> > How do I add a new record like AddNew in the System.Data.OleDb.
>> > Since there is an autonumber in the table I need this number to
>> > generate other records in other tables.



Sun, 25 Apr 2004 03:42:55 GMT  
 AddNew concept with System.Data.OleDb
Have you actually managed to insert a new record into the db? Or is it just
finding the autonumber after it's been inserted that's the problem? You
might like to mail me directly as I don't really monitor this group.


Quote:
> I am using an access db.  I have used the AddNew in ADODB to retrieve
> the last record but need the same for my .Net C# implementation.  I
> would be Ideal if someone could point me in the right direction.

> On Tue, 6 Nov 2001 08:42:27 -0000, "Martin Rogan"

> >Seeing as you're using oledb, as oppossed to the sql ones, I assume
you're
> >not using sql server. You probably won't be able to use a statement like



> >> I had this problem in my project also. What I did to resolve this is to
> >use

> >get
> >> the autonumber of the record just added.

> >> EC



> >> > How do I add a new record like AddNew in the System.Data.OleDb.
> >> > Since there is an autonumber in the table I need this number to
> >> > generate other records in other tables.



Mon, 26 Apr 2004 15:44:01 GMT  
 AddNew concept with System.Data.OleDb
I've used the data adapter wizards for sql server and they can do this stuff
automatically. Just tried the ole db ones with an Access db, and they
"tried". The wizard has a specific option to "refresh the db" to get
identities/autonumbers, defaults and other db calculated fields. It
essentially generates a sql insert statement, and follows this with a select
statement to get back the autonumber. This raises an error as access can't
handle multiple statements in one hit. I don't really know why it bothered -
the ole db stuff can't really be aware or Access' capabilities.

I used to do this in two ways with access. Either stear away from
autonumbers, or follow each insert with a select. The later is easy in some
cases (while laborious, cumbersome and unperformant), IF you've just
inserted a value/values that can uniquely identify the row by
itself/themselves. Sometimes this is not the case (and usually the reason
you're using autonumbers in the first place) so here you'll need to use some
heavyweight locks and transactions. Otherwise you could just "hope" that the
highest autonumber in the table belongs to the record you just inserted?!
Email if you want some pointers on locking.

I'd recommend steering away from autonumbers and generating your own. This
is one of the reasons I go for sql server even where it's not needed; easy
if you've got access to one. Maybe ado.net supports access xp better? No
idea. And maybe this will be fixed for the full release. Who knows? Or
perhaps there's someway of defining a query/macro in access now (didn't used
to be) that can do multiple statements (aka stored procedures).

Good luck.


Quote:
> Have you actually managed to insert a new record into the db? Or is it
just
> finding the autonumber after it's been inserted that's the problem? You
> might like to mail me directly as I don't really monitor this group.



> > I am using an access db.  I have used the AddNew in ADODB to retrieve
> > the last record but need the same for my .Net C# implementation.  I
> > would be Ideal if someone could point me in the right direction.

> > On Tue, 6 Nov 2001 08:42:27 -0000, "Martin Rogan"

> > >Seeing as you're using oledb, as oppossed to the sql ones, I assume
> you're
> > >not using sql server. You probably won't be able to use a statement
like



> > >> I had this problem in my project also. What I did to resolve this is
to
> > >use

to
> > >get
> > >> the autonumber of the record just added.

> > >> EC



> > >> > How do I add a new record like AddNew in the System.Data.OleDb.
> > >> > Since there is an autonumber in the table I need this number to
> > >> > generate other records in other tables.



Tue, 27 Apr 2004 18:56:18 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. System.Data.OleDb

2. connect to SapDB raises System.Data.OleDB error

3. scanf problem (DATA/MEMORY CONCEPT) (newbie)

4. tcxl toolbox, innovative data concepts

5. Data Entry Forms - Need Help With General Concepts !

6. AddNew on an empty Recordset fails in MS C++ AddNew Example

7. OLEDB/ADO SQL65 simple 2-tier system?

8. System.NullReferenceException bug in OleDb.Command.ExecuteReader()

9. OLEDB - How to fill ID_EDIT with data from RecordSet

10. Accessing BLOB Data with ATL OLEDB Classes

11. Wanted Opinion on VB/ADO vs C++/OLEDB Data Access

12. How to insert BLOB data into MSSQL with OLEDB templates library

 

 
Powered by phpBB® Forum Software