Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi.
i given identity to the uid its automatically increased by one...
when a new user came to register the id of his account show to him...
i used this code in page load event:

C#
con.Open();
SqlCommand cmd = new SqlCommand("select * from ownreg",con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
    TextBox10.Text = dr[0].ToString().Trim();
}
con.Close();
dr.Close();


but it showing the id as 1 only.
how to increment or display the current id number.
Posted
Updated 4-Nov-11 20:41pm
v2

SQL has it's own functionality of AutoIncrement on inseration use that.
As you insert users information your id get's incremented automatically.
check this[^]
 
Share this answer
 
Comments
Raghupathiraja 5-Nov-11 2:49am    
s i do it...
but i want show it in texbox at run time...
i coded like above... but it displaying id as 1 only...
not showing the current uid from the table....
help me friend....
koolprasad2003 5-Nov-11 2:51am    
does your id get's incremented in database successfully ?
Raghupathiraja 5-Nov-11 2:54am    
s there i gets increments...
does your id get's incremented in database successfully ?
if yes then you can get autoincremented id while inseration.

here is script.
insert into sample values('w','r') SELECT @@Identity as test


The test column will return newly inserted auto incremented value.

fectch the value and assign it to textbox.
 
Share this answer
 
Comments
Raghupathiraja 5-Nov-11 3:35am    
thank u ya...
Update this code you get the solution
C#
con.Open();
SqlCommand cmd = new SqlCommand("select max([your id field])+1 from  ownreg",con);
SqlDataReader dr = cmd.ExecuteReader();

if (dr.Read())
{
  TextBox10.Text = dr[0].ToString().Trim();
}

con.Close();
dr.Close();
 
Share this answer
 
v2
Comments
koolprasad2003 5-Nov-11 3:10am    
"select max+1" may be produce wrong output for concurrancy
Raghupathiraja 5-Nov-11 3:35am    
i got it friend... thanks ya...

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900