如何在asp.net中分配唯一的id [英] how to assign unique id in asp.net

查看:83
本文介绍了如何在asp.net中分配唯一的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以分享我为购物车创建唯一订单ID的逻辑。

解决方案

尝试:

 Guid g = Guid.NewGuid(); 



或者,您可以允许SQL使用DB中的Identity字段生成它们。


你不是。您让数据库为您创建ID。


您可以使用GUID创建一个唯一的标识符以供...进一步改进或为了满足您可以混淆GUID的长度正则表达式。





Guid guid = Guid.NewGuid();

string id = guid.ToString()。子串(0,10);

正则表达式R1 =新的正则表达式(id);

id = Regex.Replace(id,@\ s | \ - |'',);




上述代码是GUID&组合正则表达式,通过它可以创建长度为10的GUID。这将是完全独一无二的..



希望它会有所帮助..



:)

can someone share me the logic of creating unique order id for shopping cart.

解决方案

Try:

Guid g = Guid.NewGuid();


Alternatively, you could allow SQL to generate them by using an Identity field in the DB.


You don''t. You let the database create the ID for you.


You can use GUID to create a unique identifier to use... for further improvement or to cater the length you can mix up the GUID along with regex.


Guid guid = Guid.NewGuid();
string id = guid.ToString().Substring(0, 10);
Regex R1 = new Regex(id);
id = Regex.Replace(id, @"\s|\-|''", "");


the above mentioned code is the combination of GUID & regex, and through which a GUID of length 10 can be created. which will be completely uniqeu all the time..

Hope it will help..

:)


这篇关于如何在asp.net中分配唯一的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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