We help IT Professionals succeed at work.

How do i use Stored Proc to generate and return incremented primary key values?

connelvalentine
on
208 Views
Last Modified: 2010-04-23
Hi,

I'm using vb.net 2005 to create a database application with SQL server 2000 as a backend.
Here's my design. All my tables have got a standard format for the primary key. Eg. My "tbl_offices" table has got the primary key set as OFF0000001, OFF0000002, OFF0000003 and so on.
Whenever i add a new record, i want a stored procedure to be able to:
1. Connect to the offices table
2. Retrieve the records ordered by primrary key
3. Increment the last primary key number by 1.
4. Return the next primary key in the right format.

I'm new to stored procedures, so i'm NOT fully aware of how this can be done. Once the stored procedure is created, how can i store the return value in a variable in VB?

It'll be great if i can pass the table name to the procedure as a parameter, cause then i can use this one procedure to generate and return primary keys for all my tables and store them in my form.

Appreciate any help. Thanks

Best Regards,
CV
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.