Hints And Tips research knowledge archive
Tip# 405
Sponsored Links
 
Subject: TableAdapters and Identity columns!
Updated: Dec-5-2005
Rating: Not Rated
By: Rocky Moore - Member #: 1
Location: Klamath Falls, Oregon USA
Website: www.RockyMoore.com
Category: Computers > Programming > .NET > ADO.NET
Rate This Tip (10=Great):  1  2  3  4  5  6  7  8  9  10
When you create your TableAdapters with the data wizard in Visual Studio 2005, be sure to select the option for "Refresh Data" (under Advanced) if you plan to use any automatic identity columns.  If you do not, the identity value will not update in your dataset until you requery the table.

An example, let us say you want to log visits to your website.  You have sessionlog table and a requestlog table.  When a person first hits the site you add a sessionlog entry for that person.  On each page request you writh out a requestlog entry which will also contain the sessionlog entry ID for the current session.  

When you first log the sessionlog entry you simply:

* create a new row to your dataset
* set the values to all the fields except the identity column
* add the row to your dataset
* call the TableAdapter's update on the dataset
* retrieve the sessionlog identity from the data row you added
* save it off to Session State to retrieve and use on every requestlog entry.

In such a case if you have the "Refresh Data" unchecked, the identity will always be zero.  If you have it checked, you will receive the actual identity column value.

Of course, if you do not plan to use the indenty column ID of the newly added row, in your code, then you can leave this option unchecked.

[Submit DIGG for this tip]


-----------
Note: Use the tips posted on this site at your own risk. The tips are posted by the public and as such may or may not be valid.

Sponsored Links
Categories
hints and tips gold divider
Sponsor Sites To Visit
The Awakening
Spirit-Filled Christianity is
more than filling a pew !

Not producing fruit?
Healing, where to turn?
Provision, where to turn?
Lost, where to turn?

It is time for --TheAwakening !
The Saints In Light
Christian Thoughts on
Various Topics - Check it Out!

Click Here
Silverlight City

Keep up with the latest in
Microsoft's Silverlight
Technology!

Click Here
Our Local Christians
Find other Christians
In your local area
Who share your beliefs!

Click Here
United Christian Voters
Tired of seeing your
Rights Vanish?
If all Christians would
Pull together, we can
bring Change Unite Now!

Click Here
Reflected Thought
Inventions ~ Ideas ~ Humor
Politics ~ Opinions ~ Thoughts
Software Development
Business And Stuff....

Click Here
HintsnTips.com
Articles on Various Topics!

Click Here
XML RSS News Feed For Recently Posted Hints And Tips  RSS Feed
You can now get updates to the Recent Tips section by using RSS. The address is:

HintsAndTips.com/Rss.aspx

* Posting Tips *
To post a Tip, Recommendation or Tips Wanted, simply browse to the category you feel is a best fit for your post (click on the Recommention or Tips Wanted tab if fitting) and then click on "New Post" option.
(C) Copyright 1998-2009 All Rights Reserved By R & J Technologies - www.RJSoft.com