Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to handle users at the same time to get different primarkey value

how to handle users at the same time to get different primarkey value

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    developerit
    wrote on last edited by
    #1

    hi iam using asp.net2.o with c# in my application when user logins iam storing information in ordders table OrderNo int primary key (auto increment) email varchar(50) and redirects to the orders page.and in this page he will retreive the newly primary key generated and stores in session as orders. but at the same time another user logins then he is also getting the same orderno . how to handle this situation.. can you correct my code which helps me

    protected void Button1_Click(object sender, EventArgs e)
    {
    //add

        int x = 0;
       
    
        foreach (GridViewRow row in GridView1.Rows)
        {
    
    
             CheckBox c1 = (CheckBox)row.FindControl("chk");
            TextBox qt = (TextBox)row.FindControl("txtQuantity");
            TextBox tot1 = (TextBox)row.FindControl("txtTotal");
    
            Label categoryname = (Label)row.FindControl("Label1");
            Label ItemKey = (Label)row.FindControl("Label2");
            Label ItemKeyNameE = (Label)row.FindControl("Label3");
            Label CurrentQTY = (Label)row.FindControl("Label4");
            Label SalesPrice = (Label)row.FindControl("Label5");
            //=====================================================
    
    
    
            if (c1.Checked == true)
            {
               
                int chempty = 0;
    
                SqlCommand getpk = new SqlCommand("select IDENT\_CURRENT('TblOrder')", con);
                getpk.CommandTimeout = 0;
                con.Open();
                x = Convert.ToInt32(getpk.ExecuteScalar());
                Session\["order"\] = x;
                con.Close();
                //add to temp
                SqlCommand cmdtemp = new SqlCommand("Addtemp", con);
                cmdtemp.CommandType = CommandType.StoredProcedure;
                con.Open();
                cmdtemp.Parameters.AddWithValue("@OrderNo", Convert.ToInt32(x));
                cmdtemp.Parameters.AddWithValue("@CategoryNameE", categoryname.Text);
                cmdtemp.Parameters.AddWithValue("@ItemKey", ItemKey.Text);
    
                cmdtemp.Parameters.AddWithValue("@ItemKeyNameE", ItemKeyNameE.Text);
                cmdtemp.Parameters.AddWithValue("@CurrentQTY", CurrentQTY.Text);
                cmdtemp.Parameters.AddWithValue("@SalesPrice", SalesPrice.Text);
                cmdtemp.Parameters.AddWithValue("@Quantity", qt.Text);
                cmdtemp.Parameters.AddWithValue("@total", tot1.Text);
                chempty = Convert.ToInt
    
    N T 2 Replies Last reply
    0
    • D developerit

      hi iam using asp.net2.o with c# in my application when user logins iam storing information in ordders table OrderNo int primary key (auto increment) email varchar(50) and redirects to the orders page.and in this page he will retreive the newly primary key generated and stores in session as orders. but at the same time another user logins then he is also getting the same orderno . how to handle this situation.. can you correct my code which helps me

      protected void Button1_Click(object sender, EventArgs e)
      {
      //add

          int x = 0;
         
      
          foreach (GridViewRow row in GridView1.Rows)
          {
      
      
               CheckBox c1 = (CheckBox)row.FindControl("chk");
              TextBox qt = (TextBox)row.FindControl("txtQuantity");
              TextBox tot1 = (TextBox)row.FindControl("txtTotal");
      
              Label categoryname = (Label)row.FindControl("Label1");
              Label ItemKey = (Label)row.FindControl("Label2");
              Label ItemKeyNameE = (Label)row.FindControl("Label3");
              Label CurrentQTY = (Label)row.FindControl("Label4");
              Label SalesPrice = (Label)row.FindControl("Label5");
              //=====================================================
      
      
      
              if (c1.Checked == true)
              {
                 
                  int chempty = 0;
      
                  SqlCommand getpk = new SqlCommand("select IDENT\_CURRENT('TblOrder')", con);
                  getpk.CommandTimeout = 0;
                  con.Open();
                  x = Convert.ToInt32(getpk.ExecuteScalar());
                  Session\["order"\] = x;
                  con.Close();
                  //add to temp
                  SqlCommand cmdtemp = new SqlCommand("Addtemp", con);
                  cmdtemp.CommandType = CommandType.StoredProcedure;
                  con.Open();
                  cmdtemp.Parameters.AddWithValue("@OrderNo", Convert.ToInt32(x));
                  cmdtemp.Parameters.AddWithValue("@CategoryNameE", categoryname.Text);
                  cmdtemp.Parameters.AddWithValue("@ItemKey", ItemKey.Text);
      
                  cmdtemp.Parameters.AddWithValue("@ItemKeyNameE", ItemKeyNameE.Text);
                  cmdtemp.Parameters.AddWithValue("@CurrentQTY", CurrentQTY.Text);
                  cmdtemp.Parameters.AddWithValue("@SalesPrice", SalesPrice.Text);
                  cmdtemp.Parameters.AddWithValue("@Quantity", qt.Text);
                  cmdtemp.Parameters.AddWithValue("@total", tot1.Text);
                  chempty = Convert.ToInt
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Of course each user is getting the same order number, you are asking for it. Read the documentation for IDENT_CURRENT. If you want the id for the inserted record return @SCOPE_IDENTIY() from your insert stored procedure. Also, mixing inline SQL and stored procedures is asking for maintenance headaches. Pick one, preferably stored procs and us it.


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • D developerit

        hi iam using asp.net2.o with c# in my application when user logins iam storing information in ordders table OrderNo int primary key (auto increment) email varchar(50) and redirects to the orders page.and in this page he will retreive the newly primary key generated and stores in session as orders. but at the same time another user logins then he is also getting the same orderno . how to handle this situation.. can you correct my code which helps me

        protected void Button1_Click(object sender, EventArgs e)
        {
        //add

            int x = 0;
           
        
            foreach (GridViewRow row in GridView1.Rows)
            {
        
        
                 CheckBox c1 = (CheckBox)row.FindControl("chk");
                TextBox qt = (TextBox)row.FindControl("txtQuantity");
                TextBox tot1 = (TextBox)row.FindControl("txtTotal");
        
                Label categoryname = (Label)row.FindControl("Label1");
                Label ItemKey = (Label)row.FindControl("Label2");
                Label ItemKeyNameE = (Label)row.FindControl("Label3");
                Label CurrentQTY = (Label)row.FindControl("Label4");
                Label SalesPrice = (Label)row.FindControl("Label5");
                //=====================================================
        
        
        
                if (c1.Checked == true)
                {
                   
                    int chempty = 0;
        
                    SqlCommand getpk = new SqlCommand("select IDENT\_CURRENT('TblOrder')", con);
                    getpk.CommandTimeout = 0;
                    con.Open();
                    x = Convert.ToInt32(getpk.ExecuteScalar());
                    Session\["order"\] = x;
                    con.Close();
                    //add to temp
                    SqlCommand cmdtemp = new SqlCommand("Addtemp", con);
                    cmdtemp.CommandType = CommandType.StoredProcedure;
                    con.Open();
                    cmdtemp.Parameters.AddWithValue("@OrderNo", Convert.ToInt32(x));
                    cmdtemp.Parameters.AddWithValue("@CategoryNameE", categoryname.Text);
                    cmdtemp.Parameters.AddWithValue("@ItemKey", ItemKey.Text);
        
                    cmdtemp.Parameters.AddWithValue("@ItemKeyNameE", ItemKeyNameE.Text);
                    cmdtemp.Parameters.AddWithValue("@CurrentQTY", CurrentQTY.Text);
                    cmdtemp.Parameters.AddWithValue("@SalesPrice", SalesPrice.Text);
                    cmdtemp.Parameters.AddWithValue("@Quantity", qt.Text);
                    cmdtemp.Parameters.AddWithValue("@total", tot1.Text);
                    chempty = Convert.ToInt
        
        T Offline
        T Offline
        Tej Aj
        wrote on last edited by
        #3

        check this post http://opexsolution.com/forum/viewtopic.php?f=15&t=58&p=176#p176[^]

        D 1 Reply Last reply
        0
        • T Tej Aj

          check this post http://opexsolution.com/forum/viewtopic.php?f=15&t=58&p=176#p176[^]

          D Offline
          D Offline
          developerit
          wrote on last edited by
          #4

          thanks for code project team .... this logic helps me

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups