English 中文(简体)
Convert string to 服务器上的独特识别器 in asp.net
原标题:Convert string to SQL Server uniqueidentifier in asp.net

Is there any built-in method in asp.net to convert a string to a uniqueidentifier for SQL Server, just like .ToString().

我有了一个错误: 转换在从特性上传给独一无二的识别器时失败。

或者任何人都知道如何解决这一问题。 感谢。

最佳回答

<代码>准则的构造者,以<代码>载为参数。

Guid aGuid = new Guid(aString);

2. 正确确保:

A string that contains a GUID in one of the following formats ("d" represents a hexadecimal digit whose case is ignored):

32个毗连数字:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd

- 或

Groups of 8, 4, 4, 4, and 12 digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses: dddddddd-dddd-dddd-dddd-dddddddddddd - 或{dddddddd-dddd-dddd-dddd-dddddddddddd} - 或(dddddddd-dddd-dddd-dddd-dddddddddddd)

-or-

Groups of 8, 4, and 4 digits, and a subset of eight groups of 2 digits, with each group prefixed by "0x" or "0X", and separated by commas. The entire GUID, as well as the subset, is enclosed in matching braces: {0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}

全文见

你可以把你的作用作为参数:

Guid roleID = new Guid(roleIDAsString);
sqlCommand.Parameters.Add("@RoleID", SqlDbType.UniqueIdentifier).Value = roleID;
问题回答
Guid outGuid;
Guid.TryParse(stringInput, out outGuid);

Won t crash if the string is incorrectly formatted

你们可以使用

 Guid myNew = new Guid("xxxx-xxx");
string aspUserID = myObject.ProviderUserKey.ToString();
Guid userGuid = new Guid(aspUserID);

 Guid yourGuid = new Guid(yourString);

在使用前的舱面值检查

Guid g = new Guid(string) ;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签