从字符串转换为 uniqueidentifier 时 ASP.NET 转换失败

发布于 2024-08-22 06:59:40 字数 189 浏览 8 评论 0原文

我有一个表,它有一个主键(UserID),它的类型是UniqueIdentifier。 我试图在该字段中插入一个值,但我不断收到错误。

我想获取当前用户的 userID 并将其插入到 user_Details 表中,但我不断收到此错误

从字符串转换为 uniqueidentifier 时转换失败

有人可以帮助我吗?

i have a table which has a primary key (UserID) this is of type UniqueIdentifier.
im trying to insert a value into this field but i keep getting an error.

i want to get the userID of the current user and insert the into the user_Details table, but i keep getting this error

Conversion failed when converting from a character string to uniqueidentifier

can some one please help me thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈甜 2024-08-29 06:59:40

您已将参数放入字符串中,因此它不会被识别为参数。结果是您尝试将字符串“@UserID”转换为 GUID,而不是使用参数中的值。

将查询从更改

"INSERT INTO  dbo.user_Details(UserId)VALUES ('@UserID')"

为:

"INSERT INTO  dbo.user_Details(UserId)VALUES (@UserID)"

You have put the parameter inside a string, so it's not identified as a parameter. The effect is that you are trying to convert the string "@UserID" to a GUID instead of using the value in the parameter.

Change the query from

"INSERT INTO  dbo.user_Details(UserId)VALUES ('@UserID')"

to:

"INSERT INTO  dbo.user_Details(UserId)VALUES (@UserID)"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文