In userlogin history i want to dispaly the records according to username,logintime ,logouttime,formname(what all the forms users so long visited list)but here the id(i.e in my project i am using uno) is not getting incremented in database how to make it to get increment..can anyone help me with his
following is my code:
protected void Page_Load(object sender, EventArgs e)
{
int uno = 0;
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
con.Open();
string s = "select max(uno) as uno from PayLoginHistory";
SqlDataAdapter da = new SqlDataAdapter(s, con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 1)
{
uno = uno + 1;
}
if (Convert.ToString(uno) == "")
{
uno = uno + 1;
}
else
{
uno = uno + 1;
}
Session["uno"] = Convert.ToString(uno);
}
Loading
Rosi Sreenivasa ReddyPosted Jul 31, 2013, 2:28 AM
why don't go for stored procedure
create procedure proc_someName
(
@Id int=0,
@name varchar(30)=null, // we want give columns here
@status int=0
)
as
begin
if(@status=1)
if not exists(select Id from tablename where name=@name)
select @Id=isnull(Max(Id),0) + 1 from tablename
insert into table(Id,name)Values(@Id,@name)
end
end
Abhineet SrivastavaPosted Jul 31, 2013, 12:55 AM
Like this
Identity(1,1)
Means start with 1 And Increment by 1.
Abhineet SrivastavaPosted Jul 31, 2013, 12:55 AM
Sql Query-
Alter Table TableName
alter uno int identity(1
Sanjeeb LenkaPosted Jul 31, 2013, 12:19 AM
Better to do it in database side and make the uno column as identity column. so it will automatically increment the uno no need to do any coding.
for details how to add identity check this link
http://blog.sqlauthority.com/2009/05/03/sql-server-add-or-remove-identity-property-on-column/
if you want more information reply
Ravikumar GPosted Jul 30, 2013, 11:58 PM