I am just starting out with ASP.Net using VB.Net.

I am trying to build a football website for my football club that has a backend CMS system. I have the database designed with primary and foerign keys in SQL Server 2005.

I would like some help to:
1) Insert information into a table containing a primary key ?
2) Get that primary key back and then either insert into a new table with new data or to store the ID in a session ?

any help would be much appreciated


Recommended Answers

All 3 Replies

You can retrieve your primary key anytime when you want to use it as foreign key to another table, meaning you must have sub query on your stored procedures.
This might be helpfull, you can learn a lot about this

You can insert values directly in to a PK column depending on how you have the column configured but it sounds like you're referring to an autoincrementing PK value? If so you can Select SCOPE_IDENTITY() after your insert runs to return the PK's value.

You can use the scope_identity to get the latest identity inserted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.