如何在每笔交易中获得唯一的订单ID? [英] How can I get a unique Order Id on every transaction?

查看:103
本文介绍了如何在每笔交易中获得唯一的订单ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.CS文件中提到了此代码以获取订单ID,但每当有人从我的服务页面中选择不同的包时,它就会得到相同的订单ID,即10。现在,我想在每次任何用户选择任何服务时获得唯一的订单ID。



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 .

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 .

推荐答案

您可以使用GUID。请查看下面提到的文章以获取更多信息。



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


做一点点更改您的查询。

Just make little bit change in your query.
string query = @"DECLARE @MAX_Id int=null;
                 SELECT MAX_Id= MAX(OrderID) FROM Orders ;
                 SET   MAX_Id=MAX_Id +1;
                 SELECT MAX_Id;";


我是否必须将此代码放入我的.CS文件中,或者我必须修改它?
Well do i have to put this code in my .CS file or i have to Modify it ?


这篇关于如何在每笔交易中获得唯一的订单ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆