C#GUID和SQL唯一标识符 [英] C# guid and SQL uniqueidentifier

查看:269
本文介绍了C#GUID和SQL唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个GUID,并将其存储在数据库中。

I want to create a GUID and store it in the DB.

在C#中的GUID可以使用Guid.NewGuid创建()。这将创建一个128位的整数。 SQL Server有持有庞大的十六进制数字uniqueidentifier列。

In C# a guid can be created using Guid.NewGuid(). This creates a 128 bit integer. SQL Server has a uniqueidentifier column which holds a huge hexidecimal number.

是否有一个良好/ preferred方式让C#和SQL Server的GUID玩好起来呢? (即创建一个使用Guid.New(),然后使用GUID为nvarchar或其他一些领域它存储在数据库中...或者创建窗体的一些十六进制数字SQL Server正在通过其他方式预期)

Is there a good/preferred way to make C# and SQL Server guids play well together? (i.e. create a guid using Guid.New() and then store it in the database using nvarchar or some other field ... or create some hexidecimal number of the form that SQL Server is expecting by some other means)

推荐答案

SQL期待的GUID作为一个字符串。在C#下返回一个字符串,SQL是期待的。

SQL is expecting the GUID as a string. The following in C# returns a string Sql is expecting.

"'" + Guid.NewGuid().ToString() + "'"

INSERT INTO TABLE (GuidID) VALUE ('4b5e95a7-745a-462f-ae53-709a8583700a')

是应该是什么样子的SQL。

is what it should look like in SQL.

这篇关于C#GUID和SQL唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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