updated id in asp.net using sql server

Posted by Dn2010 under ASP.NET on 4/6/2012 | Points: 10 | Views : 1074 | Status : [Member] | Replies : 2
hi friends,

automatically updated id.

create table emp(_id int primary key identity(1,1))

eg

i have 10 records,

i delete first record using id

delete from emp where _id=1

it display

2
3
4

but i want to automatically updated if i delete record id 1

1
2
3
4



please give the solution for this,

thanks.




Responses

Posted by: Hariinakoti on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Whenever u r used identity property values are save like that only.so u can used to save through coding.

Thanks & Regards
Hari

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
public int maxid(string query)
{
con = new SqlConnection(ConnectionString());
if (con.State == ConnectionState.Closed)
{
con.Open();
}
int empatt;
cmd = new SqlCommand(query, con);
string stn = cmd.ExecuteScalar().ToString();

if (stn == "")
{
empatt = 1;
}
else
{
empatt = int.Parse(stn);
empatt = empatt + 1;
}
return empatt;
}

Iam using 3 tier architecture.Above code write in DAL.after that u can write below code in button click event.

bal.EmployeeAttendanceID = dal.maxid("select max(EmployeeAttendanceID) from EmployeeAtt");

Thanks & Regards
Hari

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response