0

Hi,
I am create one application using C#.net and SQL Server 2005,
In this application uses procedure,plz give me syntax how to create procedure in SQL Server and how to handle error in stored procedure.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by __avd
0

Use this

SqlConnection myConnection =
          new SqlConnection("Data Source=IPaddress;Initial Catalog=databasename;Persist Security Info=True;User ID=username;Password=password");


SqlCommand cmd = new SqlCommand("SP name", myConnection);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter par = cmd.Parameters.Add("@MESSAGE ", SqlDbType.Varchar);
        par.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add("param", SqlDbType.NVarChar, 50).Value = "**";

 myConnection.Open();
            cmd.ExecuteNonQuery();
            string strerrormes=par.Value;

Database side
IF @@ERROR <> 0
SET @MESSAGE ='FAILURE'

RETURN

Edited by Renukavani: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.