-1
sql SP



ALTER PROCEDURE arunsss 
    @suppid VARCHAR(50),
@suppname VARCHAR(50),
@dispname VARCHAR(50),
@exists bit  output
AS
SET @exists=0
BEGIN
    IF EXISTS (SELECT suppname from [supp] where suppname=@suppname)
    SET @exists=0
    ELSE
    BEGIN
    if(@suppid is null)
begin

 select @suppid= isnull(MAX(convert(int,suppid)),0)+1 from us.dbo.supp where ISNUMERIC (suppid)=1
end
INSERT INTO [us].[dbo].[supp]
           ([suppid]
           ,[suppname]
           ,[dispname])
     VALUES
           (@suppid,@suppname,@dispname)
      set @exists=1    
end
return @exists
END
GO


in code


  string connectionString = @"Server=AKBT-TM\SQL2008;Database=us;User ID=sa;Password=turner;";
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand("dbo.arunsss"))
                {

                    cmd.CommandType = CommandType.StoredProcedure;
                    conn.Open();
                    cmd.Connection = conn;
                    SqlParameter sss=cmd.Parameters.Add("@exists",SqlDbType.Bit );
                    sss.Direction=ParameterDirection.Output;
                    cmd.Parameters.AddWithValue("@suppid", DBNull.Value);
                    cmd.Parameters.AddWithValue("@suppname", "sunils");
                    cmd.Parameters.AddWithValue("@dispname", "sunils");
                    cmd.ExecuteNonQuery();
                    if (sss.Value.ToString()=="false")
                    {

                    }
          }
}

Edited by pyTony: fixed formating

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by stbuchok
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.