Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to convert parameter value from a Guid to a String

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?

like image 445
Elisabeth Avatar asked Apr 20 '10 12:04

Elisabeth


Video Answer


2 Answers

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.

like image 64
Henk Holterman Avatar answered Sep 30 '22 10:09

Henk Holterman


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!!!

like image 31
Carlos Mendible Avatar answered Sep 30 '22 09:09

Carlos Mendible