I am using the Microsoft Data Access Application Block
for .NET code to interface to our SQL database. I have a
stored procedure (CREATE procedure ixe_MarkBranchStatus
@NodeState int = 0, @rootnode uniqueidentifier = null).

I have the data for rootnode store as a string
representation of a GUID in my C# program. I use the
following code to supply the parameters:
*********************************************************
storedParams =
SqlHelperParameterCache.GetSpParameterSet
(connStr,SQL_Name);
for (int i = 0; i <
storedParams.Length; i++) {
switch
(storedParams[i].ParameterName.ToUpper()) {

case "@NODESTATE":

storedParams[i].Value = newStatus;

break;

case "@ROOTNODE":

storedParams[i].Value = GUID;

break;
}
}
if
(SqlHelper.ExecuteNonQuery
(connStr,CommandType.StoredProcedure,SQL_Name,storedParams)
> 0) return true;

***********************************************************

The SQLHelper (Microsoft supplied code) bubbles up an
error: Invalid cast from System.String to System.Guid.
The line that causes the error is:

int retval = cmd.ExecuteNonQuery();

but a lot has gone on before this.

This was not a problem until I recently converted from
VS .NET, framework 1.0 to VS 2003, framework 1.1

Re: GUID as parameter to stored proc causes Invalid Cast by William

William
Wed Dec 17 17:02:02 CST 2003

Which line is raising the exception? Are you sure that you are setting the
value (ie, stepped through or confirmed that you are in fact hitting the
line which is setting the value). It's an easy thing to do.

Also, I'm not sure the specifics of what you are trying to do, but why
update the GUID? If you set the type on your server, then it will set
whenever you have an insert and then you can be sure it's unique across all
servers if you replicate for instance.
"Robert Storrs" <robert.storrs@intellinex.com> wrote in message
news:006601c3c4cd$c57d2a40$a501280a@phx.gbl...
> I am using the Microsoft Data Access Application Block
> for .NET code to interface to our SQL database. I have a
> stored procedure (CREATE procedure ixe_MarkBranchStatus
> @NodeState int = 0, @rootnode uniqueidentifier = null).
>
> I have the data for rootnode store as a string
> representation of a GUID in my C# program. I use the
> following code to supply the parameters:
> *********************************************************
> storedParams =
> SqlHelperParameterCache.GetSpParameterSet
> (connStr,SQL_Name);
> for (int i = 0; i <
> storedParams.Length; i++) {
> switch
> (storedParams[i].ParameterName.ToUpper()) {
>
> case "@NODESTATE":
>
> storedParams[i].Value = newStatus;
>
> break;
>
> case "@ROOTNODE":
>
> storedParams[i].Value = GUID;
>
> break;
> }
> }
> if
> (SqlHelper.ExecuteNonQuery
> (connStr,CommandType.StoredProcedure,SQL_Name,storedParams)
> > 0) return true;
>
> ***********************************************************
>
> The SQLHelper (Microsoft supplied code) bubbles up an
> error: Invalid cast from System.String to System.Guid.
> The line that causes the error is:
>
> int retval = cmd.ExecuteNonQuery();
>
> but a lot has gone on before this.
>
> This was not a problem until I recently converted from
> VS .NET, framework 1.0 to VS 2003, framework 1.1
>
>
>