C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




ID Auto Generation


Posted Date: 11 Sep 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: Geetha       Member Level: Gold
Rating:     Points: 10



We need to auto generate ID's say Employee ID, Student ID etc , in order to avoid the duplication.

The below piece of code will give you a idea about ID Auto generation.
Here have to select the max value of the id and have to increment it accordingly.




int iJobid = 0;
SqlConnection sqlCon = new SqlConnection(""Database=Master;Server=in123;User ID=sa;Password=sa123;");
sqlCon.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlCon;
sqlCmd.CommandText = "Select Max(EmpID) from EmployeeDetails";
iJobid = (int) sqlCmd.ExecuteScalar();
sqlCon.Close();
if (iJobid > 0)
iJobid = iJobid + 1;
else
iJobid = 1;
txtEmpID.Text = iJobid.ToString();






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Auto Generation  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Insert multiple records using single command
Previous Resource: How to use DataRelation in ADO.NET
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use