Dovberman
asked on
Conversion failed when converting from a character string to uniqueidentifier.
I am trying to pass a parameter from ASP.NET to a SQL Server Stored procedure.
string strUserID = currentUser.ProviderUserKe y.ToString ();
Returns "ba275a68-9e77-4301-9d97-7 cc7dfecda0 d"
SqlCommand cmd = new SqlCommand("usp_addWatchLi st", conStockSelect);
cmd.Parameters.Add("@UserI D", SqlDbType.VarChar).Value = strUserID;
cmd.ExecuteNonQuery();
Conversion failed when converting from a character string to uniqueidentifier.
---------
Stored procedure executes successfully from SQL Server Manager
ALTER PROCEDURE [dbo].[usp_addWatchList]
@SymbolID int,
@UserID varchar(50)
/*
exec usp_addWatchList
@SymbolID =329,
@UserID = 'BA275A68-9E77-4301-9D97-7 CC7DFECDA0 D'
*/
What am I missing?
Thanks,
string strUserID = currentUser.ProviderUserKe
Returns "ba275a68-9e77-4301-9d97-7
SqlCommand cmd = new SqlCommand("usp_addWatchLi
cmd.Parameters.Add("@UserI
cmd.ExecuteNonQuery();
Conversion failed when converting from a character string to uniqueidentifier.
---------
Stored procedure executes successfully from SQL Server Manager
ALTER PROCEDURE [dbo].[usp_addWatchList]
@SymbolID int,
@UserID varchar(50)
/*
exec usp_addWatchList
@SymbolID =329,
@UserID = 'BA275A68-9E77-4301-9D97-7
*/
What am I missing?
Thanks,
sorry - don't think I read it properly - the other problem you could be having is it not putting the value into the parameter right. I always add parameters like this:
cmd.Parameters.AddWithValu e("@UserID ", strUserID);
I've had problems in the past the other way where the value was not actually stored in the parameter object properly.
cmd.Parameters.AddWithValu
I've had problems in the past the other way where the value was not actually stored in the parameter object properly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I set everything to uniqueidentifier.
Error: Failed to convert parameter value from a String to a Guid.
Also tried cmd.Parameters.AddWithValu e("@UserID ", strUserID);
Error:Conversion failed when converting from a character string to uniqueidentifier.
Error: Failed to convert parameter value from a String to a Guid.
Also tried cmd.Parameters.AddWithValu
Error:Conversion failed when converting from a character string to uniqueidentifier.
ASKER
I set everything to uniqueidentifier.
AND
Also tried cmd.Parameters.AddWithValu e("@UserID ", strUserID);
AND changed the sp from this:
INSERT INTO WatchList
(UserID,SymbolID,PickDateP rice,PickD ate,Market ID)
VALUES('@UserID',@SymbolID ,23.45,'20 09-04-23', 3)
To this:
INSERT INTO WatchList
(UserID,SymbolID,PickDateP rice,PickD ate,Market ID)
VALUES(@UserID,@SymbolID,2 3.45,'2009 -04-23',3)
Now it works.
Thanks
AND
Also tried cmd.Parameters.AddWithValu
AND changed the sp from this:
INSERT INTO WatchList
(UserID,SymbolID,PickDateP
VALUES('@UserID',@SymbolID
To this:
INSERT INTO WatchList
(UserID,SymbolID,PickDateP
VALUES(@UserID,@SymbolID,2
Now it works.
Thanks
Like this:
cmd.Parameters.Add("@UserI