I am having an issue regarding the use of output parameters in a SQL Stored Procedure.
I want to be able to pass a string to a Stored Procedure and have it return a string for processing in my C# app.
The code that I have is this:
----------
public static bool clStatus(string strClient)
{
try
{
strSQL = "sp_DCS_CLStatus";
SqlCommand oCommand = new SqlCommand(strSQL,eliteConnection);
oCommand.CommandType = CommandType.StoredProcedure;
//input
SqlParameter inParam = new SqlParameter();
inParam = oCommand.Parameters.Add("@CliNum",SqlDbType.VarChar,10);
inParam.Direction = ParameterDirection.Input;
inParam.Value = strClient;
//output
SqlParameter outParam = new SqlParameter();
outParam = oCommand.Parameters.Add("@clStatus",SqlDbType.VarChar,10);
outParam.Direction = ParameterDirection.Output;
//SqlDataReader reader = oCommand.ExecuteReader();
oCommand.ExecuteNonQuery();
/*
string clstatus = outParam.Value.ToString();
switch(clstatus)
{
case "C":
return true;
break;
default:
return false;
break;
}
*/
}
catch(Exception E)
{
Console.WriteLine(E.Message + E.StackTrace );
return false;
}
return false;
}
----------
The SQL Stored Procedure looks like this:
----------
CREATE procedure sp_DCS_CLStatus
@clStatus varchar(10) output,
@CliNum varchar(10)
as
set @clStatus =
(
select clstatus from client where clnum = @CliNum
)
return @clStatus
GO
----------
When I run this, the message that I get is:
----------
Syntax error converting the varchar value 'Z' to a column of data type int. at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, Run
Behavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at dcsValidator.clStatus(String strClient) in d:\dev\validator\validator.cs:l
ine 238
-----------
Any help would be greatly appreciated.
Thanks,
Mark
I want to be able to pass a string to a Stored Procedure and have it return a string for processing in my C# app.
The code that I have is this:
----------
public static bool clStatus(string strClient)
{
try
{
strSQL = "sp_DCS_CLStatus";
SqlCommand oCommand = new SqlCommand(strSQL,eliteConnection);
oCommand.CommandType = CommandType.StoredProcedure;
//input
SqlParameter inParam = new SqlParameter();
inParam = oCommand.Parameters.Add("@CliNum",SqlDbType.VarChar,10);
inParam.Direction = ParameterDirection.Input;
inParam.Value = strClient;
//output
SqlParameter outParam = new SqlParameter();
outParam = oCommand.Parameters.Add("@clStatus",SqlDbType.VarChar,10);
outParam.Direction = ParameterDirection.Output;
//SqlDataReader reader = oCommand.ExecuteReader();
oCommand.ExecuteNonQuery();
/*
string clstatus = outParam.Value.ToString();
switch(clstatus)
{
case "C":
return true;
break;
default:
return false;
break;
}
*/
}
catch(Exception E)
{
Console.WriteLine(E.Message + E.StackTrace );
return false;
}
return false;
}
----------
The SQL Stored Procedure looks like this:
----------
CREATE procedure sp_DCS_CLStatus
@clStatus varchar(10) output,
@CliNum varchar(10)
as
set @clStatus =
(
select clstatus from client where clnum = @CliNum
)
return @clStatus
GO
----------
When I run this, the message that I get is:
----------
Syntax error converting the varchar value 'Z' to a column of data type int. at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, Run
Behavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at dcsValidator.clStatus(String strClient) in d:\dev\validator\validator.cs:l
ine 238
-----------
Any help would be greatly appreciated.
Thanks,
Mark