Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO.Net SQL Stored Procedure Output Parameters Help

Status
Not open for further replies.

Mierk

Programmer
Apr 4, 2002
7
US
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top