Click here to Skip to main content
15,921,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 this. Following is my code:
C#
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);
   }
Posted
Updated 30-Jul-13 18:15pm
v2
Comments
[no name] 30-Jul-13 21:41pm    
If the value is not getting incremented in the database, is it set to be auto incremented?
What is the point of this code? You query a database and then do nothing with the result...
syed shanu 30-Jul-13 22:00pm    
I think you need to change your code like this

if (dt.Rows.Count > 0)
{
uno = Convert.ToInt32(dt.Rows[0][0].ToString()) + 1;
}

and below code i think its no need
if (Convert.ToString(uno) == "")
{
uno = uno + 1;
}
else
{
uno = uno + 1;
}
Thanks7872 31-Jul-13 0:19am    
You have made changes in uno the way you want. You want it to be incremented in database,so you have to update it in database.I didnt find that code in above codeblock. Or you can make it identity field in database as ryanb31 suggested in below solution.

1 solution

Is your field an identity field? If so, it is getting incremented. You'll want to return it from your stored procedure using SCOPE_IDENTITY().

If it is not identity field then you'll need to get the MAX(ID) + 1 and update it yourself.
 
Share this answer
 
Comments
deepa ashwi 30-Jul-13 23:59pm    
no its not an identity field
ZurdoDev 31-Jul-13 7:42am    
OK, so in your stored procedure you can set the value to MAX(ID) + 1

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