invisible kid
03-18-2006, 08:11 AM
When calling a stored procedure, I get the following error:
"Syntax error converting the varchar value 'value' to column of datatype int"
But it doesn't make sense, as none of the columns I am referencing are of type int, and I am declaring my return parameter to be of type 'varchar'.
The stored procedure is as follows:
ALTER PROCEDURE sp_GetUserDetails /* How it would appear in QUERY ANALYZER */
(
@UserName VARCHAR(50) = NULL,
@ReturnFirstName VARCHAR(50) = NULL
)
AS
SET @ReturnFirstName = (SELECT FirstName FROM tblUser
WHERE UserName = @UserName)
RETURN @ReturnFirstName
and the code used to call it is:
public string FirstName(string txtUser)
{
SqlConnection myConn2 = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCmd2 = new SqlCommand("sp_GetUserDetails", myConn2);
myCmd2.CommandType = CommandType.StoredProcedure;
SqlParameter objParam3;
SqlParameter returnParam2;
objParam3 = myCmd2.Parameters.Add ("@UserName", SqlDbType.VarChar);
returnParam2 = myCmd2.Parameters.Add ("@ReturnFirstName", SqlDbType.VarChar);
objParam3.Direction = ParameterDirection.Input;
returnParam2.Direction = ParameterDirection.ReturnValue;
objParam3.Value = txtUser;
if (myConn2.State.Equals(ConnectionState.Closed))
{
myConn2.Open();
myCmd2.ExecuteNonQuery();
}
else
{
myConn2.Close();
return (string)returnParam2.Value;
}
return (string)returnParam2.Value;
Any help greatly appreciated!
"Syntax error converting the varchar value 'value' to column of datatype int"
But it doesn't make sense, as none of the columns I am referencing are of type int, and I am declaring my return parameter to be of type 'varchar'.
The stored procedure is as follows:
ALTER PROCEDURE sp_GetUserDetails /* How it would appear in QUERY ANALYZER */
(
@UserName VARCHAR(50) = NULL,
@ReturnFirstName VARCHAR(50) = NULL
)
AS
SET @ReturnFirstName = (SELECT FirstName FROM tblUser
WHERE UserName = @UserName)
RETURN @ReturnFirstName
and the code used to call it is:
public string FirstName(string txtUser)
{
SqlConnection myConn2 = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCmd2 = new SqlCommand("sp_GetUserDetails", myConn2);
myCmd2.CommandType = CommandType.StoredProcedure;
SqlParameter objParam3;
SqlParameter returnParam2;
objParam3 = myCmd2.Parameters.Add ("@UserName", SqlDbType.VarChar);
returnParam2 = myCmd2.Parameters.Add ("@ReturnFirstName", SqlDbType.VarChar);
objParam3.Direction = ParameterDirection.Input;
returnParam2.Direction = ParameterDirection.ReturnValue;
objParam3.Value = txtUser;
if (myConn2.State.Equals(ConnectionState.Closed))
{
myConn2.Open();
myCmd2.ExecuteNonQuery();
}
else
{
myConn2.Close();
return (string)returnParam2.Value;
}
return (string)returnParam2.Value;
Any help greatly appreciated!