Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have mentioned this Code in .CS file to get an Order id but every time when someone choose different packages from my Services Page so its get me the same Order Id which is 10 . now i want to get a unique Order Id on every time when any user choose any of the Services .

C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           AmountBox.Text = Request.QueryString[0].ToString();
           lblCustNotes.Text = Request.QueryString[1].ToString();
           lblOrderId.Text = OrderID().ToString();
       }
   }
   protected int OrderID()
   {
       string query = "SELECT MAX(OrderID) FROM Orders";
       int id = Query.Scaller(query, 0);
       return id + 000;
   }
   protected void btnSubmit_Click(object sender, EventArgs e)
   {
       Response.Redirect("~/SubmitData.aspx?x=" + AmountBox.Text + "&y=" + lblCustNotes.Text+"&z="+lblOrderId.Text);
   }


Do let me know the Solution so i can complete this Project .
Posted
Updated 27-Jan-14 20:30pm
v2
Comments
Sampath Lokuge 28-Jan-14 3:31am    
You have to modify it according to your situation (i.e. Solution 1).

You can use GUID for that.Please check below mentioned article for more info.

// This code example demonstrates the Guid.NewGuid() method. 

using System;

class Sample 
{
    public static void Main() 
    {
    Guid g;
// Create and display the value of two GUIDs.
    g = Guid.NewGuid();
    Console.WriteLine(g);
    Console.WriteLine(Guid.NewGuid());
    }
}

/*
This code example produces the following results:

0f8fad5b-d9cb-469f-a165-70867728950e
7c9e6679-7425-40de-944b-e07fc1f90ae7

*/


Guid
 
Share this answer
 
Just make little bit change in your query.
C#
string query = @"DECLARE @MAX_Id int=null;
                 SELECT MAX_Id= MAX(OrderID) FROM Orders ;
                 SET   MAX_Id=MAX_Id +1;
                 SELECT MAX_Id;";
 
Share this answer
 
v4
Well do i have to put this code in my .CS file or i have to Modify it ?
 
Share this answer
 

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