Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
USE [security]
GO
/****** Object: StoredProcedure [dbo].[exam] Script Date: 10/15/2013 23:15:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[exam]
@type varchar(50)=null,
@user_name varchar(50)=null,
@email_id varchar(50)=null,
@password varchar(50)=null,
@exp varchar(50)=null
as
begin
if(@type='insert')
begin

insert into user_info values(@user_name,@email_id,@password,@exp)
end
if(@type='select')
begin

if exists(select @email_id,@password from user_info where email_id=@email_id and password=@password)
select @email_id,@password from user_info where email_id=@email_id and password=@password
end
end
Posted
Comments
sanjiv yadav 15-Oct-13 13:49pm    
how to call these store procedure

This creates, uses and removes a stored procedure:
C#
string r;
string s;
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand create = new SqlCommand("CREATE PROC [dbo].Sample @Name varchar(100) OUTPUT AS BEGIN SELECT @Name=Username FROM myTable WHERE iD=1 END", con))
        {
        create.ExecuteNonQuery();
        }
    using (SqlCommand com = new SqlCommand("Sample", con))
        {
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter name = new SqlParameter("@Name", SqlDbType.VarChar, 100);
        name.Direction = ParameterDirection.Output;
        com.Parameters.Add(name);
        com.ExecuteNonQuery();
        r = (string) name.Value;
        s = (string) com.Parameters["@Name"].Value;
        }
    using (SqlCommand drop = new SqlCommand("DROP PROCEDURE [dbo].Sample", con))
        {
        drop.ExecuteNonQuery();
        }
    con.Close();
    }
Console.WriteLine("Name : {0}\nParam: {1}", r, s);
 
Share this answer
 
this is for class.
C#
using Microsoft.ApplicationBlocks.Data;
using Microsoft.ApplicationBlocks.ExceptionManagement;

public string connection()
{
    return ConfigurationSettings.AppSettings["connection"];
}

public SqlDataReader GetData(string type, string username, string email, string password, string exp)
{
    SqlDataReader sqlReader = SqlHelper.ExecuteReader(connection(), CommandType.StoredProcedure, "exam",
        new SqlParameter("@type", type),
        new SqlParameter("@username, username"),
        new SqlParameter("@email", email),
        new SqlParameter("@password", password),
        new SqlParameter("@exp", exp));
    return sqlReader;
}


this is the most simplest way to do it. Hope this helped.
 
Share this answer
 
Create the store procedure in SQL and call this in your code.

public void methodName(string parameter1,string parameter2)
{
SqlConnection con = new SqlConnection("Data Source=server_name;Initial Catalog=Database_name;User ID=username;Password=password");
con.Open();
SqlConnection.ClearAllPools();

SqlCommand cmd = new SqlCommand("Stored Procedure Name", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@param1", SqlDbType.VarChar, 50));
cmd.Parameters[0].Value = parameter1;

cmd.Parameters.Add(new SqlParameter("@param2", SqlDbType.VarChar, 50));
cmd.Parameters[1].Value = parameter2;

SqlDataReader rdr = cmd.ExecuteReader();


return rdr.Read();

con.Close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900