Working With SqlParameter in .NET

  • It should be noted that the “@” symbol is a syntax flag for parameters in the SQL CommandString, and is not part of the actual Parameter Name. The .Add methods will accept the name with or without the “@” symbol for convenience, but it’s not technically proper to include it since it isn’t really part of the name.

  • Hi,

    I'm new to ASP.NET and ADO.NET and was just trying out SqlParameter. How do I use SqlParameter to get a return code along with other parameters (input). I have a stored procedure that accepts some parameters to insert new record in a table.

    I need to get the return code whether my insert execution is successful or not. So how do I get the return code?

    Thanks in a million.

  • Halim Dahlan (12/5/2007)


    Hi,

    I'm new to ASP.NET and ADO.NET and was just trying out SqlParameter. How do I use SqlParameter to get a return code along with other parameters (input). I have a stored procedure that accepts some parameters to insert new record in a table.

    I need to get the return code whether my insert execution is successful or not. So how do I get the return code?

    Thanks in a million.

    Sorry I don't usually use myself but as I recall if you have a return code the parameter collection of the SqlCommand object will contain it in the 0 item or @ret item so something like this in C# (assuming your SqlCommand object is named cmdSQL)

    cmdSQL.Parameters[0]...

    or

    cmdSQL.Parameters["@ret"]...

  • Try the following code, it should get you started:

    SqlCommand cmd = new SqlCommand("usp_Table_Action");

    cmd.CommandType = CommandType.StoredProcedure;

    SqlParameter param = new SqlParameter("@ReturnCode", SqlDbType.Int);

    param.Direction = ParameterDirection.ReturnValue;

    cmd.Parameters.Add(param);

  • Hey thanks a lot programmer. It worked.

Viewing 5 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic. Login to reply