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

Ravikumar G178 reputationPosted Jul 30, 2013, 7:58 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 8:19 PM EDT
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
Abhineet SrivastavaRank #1,890 · 783 reputationPosted Jul 30, 2013, 8:55 PM EDT
Sql Query-
Alter Table TableName
alter uno int identity(1
Abhineet SrivastavaRank #1,890 · 783 reputationPosted Jul 30, 2013, 8:55 PM EDT
Like this
Identity(1,1)
Means start with 1 And Increment by 1.
Rosi Sreenivasa Reddy137 reputationPosted Jul 30, 2013, 10:28 PM EDT
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