无法将参数值从Guid转换为String

Eli*_*eth 5 c# string datatable guid

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

一周前一切都运作良好.

我对存储库进行了还原,重新创建了tableadapter等......没有任何帮助.

当我尝试保存在我的应用程序中时,此时我得到一个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**
    }
}
Run Code Online (Sandbox Code Playgroud)

一切都被困在这里,因为Guid - 我用放大镜工具检查数据表预览它真的是数据表列中的真正Guid - 无法转换为字符串??? 怎么会发生这种情况?

Hen*_*man 6

这是相反的方式.您的userId是一个字符串,您需要参数的GUID值:

 Parameters["@userId"].Value = new Guid(userId);
Run Code Online (Sandbox Code Playgroud)

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

根据以下评论进行修改:

事实证明,您正在询问如何运行如下的选择语句:

SELECT ....
WHERE '{BB6DFF45-FDA7-4155-86D0-0CBF129A9104}' = `domainname\\jondoe`
Run Code Online (Sandbox Code Playgroud)

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