无法将参数值从 Guid 转换为字符串

发布于 2024-08-29 09:00:17 字数 728 浏览 2 评论 0原文

我的知识已经结束了,也用谷歌搜索了答案,但没有运气:/

一周前一切都运行良好。

我在存储库上进行了恢复,重新创建了表适配器等......没有任何帮助。

当我尝试在应用程序中保存时,此时出现 SystemInvalidCastException:

PersonListDataSet.cs:

partial class P_GroupTableAdapter
{
    public int Update(PersonListDataSet.P_GroupDataTable dataTable, string userId)
    {
        this.Adapter.InsertCommand.Parameters["@userId"].Value = userId;
        this.Adapter.DeleteCommand.Parameters["@userId"].Value = userId;
        this.Adapter.UpdateCommand.Parameters["@userId"].Value = userId;

        return this.Update(dataTable); **<-- Exception occurs here**
    }
}

Everything is 卡在这里,因为 Guid - 我使用放大镜工具检查了数据表预览,它确实是数据表列中的真正 Guid -无法转换为字符串???怎么会这样呢?

I am at the end of my knowledge and googled for the answer too but no luck :/

Week ago everything worked well.

I did a revert on the repository, recreated the tableadapter etc... nothing helped.

When I try to save in my application I get an SystemInvalidCastException at this point:

PersonListDataSet.cs:

partial class P_GroupTableAdapter
{
    public int Update(PersonListDataSet.P_GroupDataTable dataTable, string userId)
    {
        this.Adapter.InsertCommand.Parameters["@userId"].Value = userId;
        this.Adapter.DeleteCommand.Parameters["@userId"].Value = userId;
        this.Adapter.UpdateCommand.Parameters["@userId"].Value = userId;

        return this.Update(dataTable); **<-- Exception occurs here**
    }
}

Everything is stuck here because a Guid - and I checked the datatable preview with the magnifier tool its really a true Guid in the column of the datatable - can not be converted to a string ??? How can that happen?

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

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

发布评论

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

评论(2

甜味拾荒者 2024-09-05 09:00:17

恰恰相反。您的 userId 是一个字符串,您的参数需要一个 GUID 值:

 Parameters["@userId"].Value = new Guid(userId);

提供的 UserId 是 GUID 支持的格式之一。构造函数支持多种格式

根据下面的评论进行编辑:

事实证明,您是在询问如何运行这样的选择语句:

SELECT ....
WHERE '{BB6DFF45-FDA7-4155-86D0-0CBF129A9104}' = `domainname\\jondoe`

我认为您应该重新检查您的数据模型并找到解决方案。

It's the other way around. Your userId is a string and you need a GUID value for your parameters:

 Parameters["@userId"].Value = new Guid(userId);

Provided UserId is in one of the supported formats for a GUID. The constructor supports many formats.

Edit, based on comments below:

It turns out that you are asking how to run a select statement like:

SELECT ....
WHERE '{BB6DFF45-FDA7-4155-86D0-0CBF129A9104}' = `domainname\\jondoe`

I think you should re-check your datamodel and find a solution.

粉红×色少女 2024-09-05 09:00:17

您尝试过吗:

this.Adapter.InsertCommand.Parameters["@userId"].Value = new Guid(userId);
this.Adapter.DeleteCommand.Parameters["@userId"].Value = new Guid(userId);
this.Adapter.UpdateCommand.Parameters["@userId"].Value = new Guid(userId);

希望有帮助!

Have you tried:

this.Adapter.InsertCommand.Parameters["@userId"].Value = new Guid(userId);
this.Adapter.DeleteCommand.Parameters["@userId"].Value = new Guid(userId);
this.Adapter.UpdateCommand.Parameters["@userId"].Value = new Guid(userId);

Hope it helps!!!

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