Thursday, 3 August 2017

Flow Chart Factorial Number

SQL Server output parameter


Output Parameter

Store procedure is a set of some sql statement which saved on server. Store procedure takes argument for database operation which is known parameter. There are two type of parameter.

Input parameter

When user provides a value as parameter and passes to store procedure.

Output Parameter

When user hold something returns from store procedure through parameter known as output parameter.

Advantage

  • Decrease complexity because it help you to do more than one task in single procedure
  • when inserting data to a table and you need to get the identity value back
  • when perfoming select statements and you need some extra data,
  • when updating or inserting data and you need some way to know if the operation was successful
  • for most if not all of the reasons you need out or ref parameters in c#




Store Procedure

USE [Girfa]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[pcheck]
(
@id bigint,
@phone varchar(15) output
)

as
as


select @phone= MobileNo from dbo.UserMaster where UserId=@id

C# Code

UserModel ob = new UserModel();

try

 {

    using (SqlConnection dbCon = new  SqlConnection(ConfigurationManager.ConnectionStrings["dbConnection"].ToString()))

    {

 

        using (SqlCommand cmd = new SqlCommand("[dbo].[pcheck]", dbCon))

        {

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@id", Convert.ToInt32(id));

            cmd.Parameters.Add("@phone", SqlDbType.VarChar, 30);

            cmd.Parameters["@phone"].Direction = ParameterDirection.Output;

            if (dbCon.State == ConnectionState.Closed)

                    dbCon.Open();

            cmd.ExecuteNonQuery();

            b.MobileNo = Convert.ToString(cmd.Parameters["@phone"].Value);

        }

 

     }

}

catch (Exception ex)

{

              

}

 

return ob;




Wednesday, 2 August 2017

Passing Array to function


Q : Write a function which accepts an array of size n containing integer values and returns average of all values. Call the function from main program.

Solution :


#include<stdio.h>
#include<conio.h>
int avg(int[],int);
void main()
{
     int ar[5],i;
     clrscr();
     for(i=0;i<5;i++)
     {
          printf("Enter %d number

Write a program to bonus calculation using structure

Q : Write a C program to store the employee details with the following attribute?



Sr No.
Basic Salary
Sales Percentage
Bonus Amount
1
<=7000
<=10
1500
2
<=7000
>=10
3000
3
>7000 and <=15000
<=10
2000
4
>7000 and <=15000
>=10
4000
5
>15000
<=10
2500
6
>15000
>=10
4500

Solution : 


/* ============================================
          Girfa Student Help
          Program : Salary Calculation
          For more program visit :http://girfahelp.blogspot.in/p/c-language-structure-programming.html
================================================*/
#include<stdio.h>
#include<conio.h>
typedef struct stu
{
     int empid;
     int pf;
     int mediclaim;
     int basicsal;
     int sp;