Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server C#4.0
Hi friends,
I created sql table with studentID column as a autoincreamented column.now I want to show the Id from sql to textbox.Before any insertion of data there is no Id on the table. At that time I want show First value in textbox and then show next autoincremented value from sql table for every insertion.Plase help me how can i do this.
Thanks in advance
Posted 12-Oct-12 21:20pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Don't.
Stop and think about it.
Why are you showing the value at all? So that people know what value will be assigned to the new record they are creating. But the main reason for using SQL is that it supports multiple users at the same time, so the "next value" won't be the next one - that value may have been used by a different user two hours ago.
 
That leads to confusion - only show information when it will be correct - which in the case of auto incremented data is only after the record has been inserted correctly.
 
If you need to give the user the record id, then there is probably something wrong with your data design.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 445
1 CHill60 410
2 Sergey Alexandrovich Kryukov 354
3 BillWoodruff 190
4 PIEBALDconsult 160


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100