CREATE PROCEDURE [dbo].[MyProcedure]
@Order_ID int,
@ReturnMessage varchar(250) OUTPUT
AS
If exists(select Fname from table where condition)
Begin
Insert into Table1(Fname)
values(
Select @ReturnMessage ="It exists and Fname inserted"
return @ReturnMessage
End
Select @ReturnMessage ="It does not exists"
return @ReturnMessage
GO
I want to call this Procedure from C#Application & return the valueof ReturnMessage in my application
Java
SqlParameter paramOrderId = new SqlParameter("@Order_ID", SqlDbType.Int);
paramOrderId.Value = Order_ID;
SqlParameter paramRetMsg = new SqlParameter("@ReturnMessage", SqlDbType.Int );
paramRetMsg.Direction = ParameterDirection.Output;
ReturnMessage = Convert.ToInt32(SqlHelper.ExecuteScalar(ds._conStringCCR, CommandType.StoredProcedure, "MyProcedure", paramOrderId, paramRetMsg));and I am not able to return the value to the application .
Please let me know whats wrong.
pujain6 pointsPosted Jul 26, 2006, 10:19 AM EDT
Now i am trying this .. But it gives me error : Cannot implicitly convert type 'System.Data.SqlClient.SqlDataReader' to 'string'
public static string GetMsg(int Order_ID)
{
DataAccess ds = new DataAccess();
String ReturnMessage = string.Empty;
try
{
SqlParameter paramOrderId = new SqlParameter("@Order_ID", SqlDbType.Int);
paramOrderId.Value = Order_ID;
SqlParameter paramRetMsg = new SqlParameter("@ReturnMessage", SqlDbType.VarChar,250);
paramRetMsg.Direction = ParameterDirection.Output;
ReturnMessage =(SqlHelper.ExecuteReader(ds._conStringCCR, CommandType.StoredProcedure, "MyProcedure", paramOrderId, paramRetMsg));
}
}
Please let me know .
arvind haritus83 pointsPosted Jul 27, 2006, 1:47 AM EDT
please try this, may be help you
ReturnMessage =(SqlHelper.ExecuteReader(ds._conStringCCR, CommandType.StoredProcedure, "MyProcedure", paramOrderId, paramRetMsg)).ToString();
paresh jagatiya4 pointsPosted Jul 27, 2006, 2:11 AM EDT
1st : no need to have
return @ReturnMessage
just use
Select @ReturnMessage ="It exists and Fname inserted"
and try following..
ReturnMsg = SqlHelper.ExecuteScaler(......).ToString();
(As Executescaler gives you Object type)
2nd :
Returnmessage = paramRetMsg.value;
(before you access the value of output param the connection need to be closed).
pujain6 pointsPosted Jul 27, 2006, 5:38 AM EDT
Arvind,
Thanks for the reply, But when I use t , instead of the value of return message it has
'"System.Data.SqlClient.SqlDataReader" in the retrun message.
let me know