Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2007, 01:37 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default AutoIncrement

Hi,

I've got an ID column in a dataTable that has auto-increment set to True. Yet for some reason when I add a new row that column maintains a value of DBNull! What's up with that?

Here is my code:

When Filling the table...
Code:
'First column, "PromoteID" is set as an identity in DB
da.FillSchema(dsTracking, SchemaType.Source)
da.Fill(dsTracking, "Tracking")
When adding a row later on...
Code:
'add a new record to Tracking table
Dim dr As DataRow = dsTracking.Tables("Tracking").NewRow
dr("EmployeeID") = EmployeeID.Text
dr("ChangeDate") = Today
dsTracking.Tables("Tracking").Rows.Add(dr)
When I debug, both dr("PromoteID") is DBNull and so is dsTracking.Tables("Tracking").Rows(...last row...)("PromoteID") after I add dr to the table.

One thing which might be significant is that I'm storing the dataset in the cache, and then retrieving it on postbacks.

Please help? My client is waiting none too patiently.

Aaron

 
Old February 7th, 2007, 01:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

I never do this in that way.. but don't you have to commit the changes to the db using AcceptChanges??

because you are only seeing the cached data and not the real db data...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old February 7th, 2007, 01:53 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks for responding.

If I commit the changes using dsTracking.AcceptChanges, then I won't be able to commit them back to the database later.

In this case, seeing the cached data is actually okay.

Thanks.

Aaron

 
Old February 7th, 2007, 02:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

but you need to tell the db to add the row so it can produce the autoincrement field...

remember that the datatable is not bounded to the db so it doesn't know that you add a row... if you look at the field definition of the datatable that particular field has only data type, and the auto increment is a db functionality...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old February 7th, 2007, 02:16 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Really? You're sure? Wow. Is there no way to simulate an AutoIncrement column in a disconnected dataset then?

Aaron

 
Old February 7th, 2007, 02:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

almost almost sure...

but we need an sql expert here so he/she can check this out..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
dataset and autoincrement primary key be03024 ADO.NET 8 July 19th, 2009 12:09 PM
setting autoincrement tbecker82 Access 3 June 20th, 2006 01:17 PM
PrimaryKeys, AutoIncrement gbilios VB.NET 2002/2003 Basics 4 June 9th, 2005 07:31 AM
Generated dataset and autoincrement dbradley ADO.NET 5 February 2nd, 2005 01:14 AM
Autoincrement field not incrementing leo_vinay SQL Server ASP 1 January 4th, 2005 08:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.