create procedure getempproc @city varchar(20)
as
begin
select * from emp where city=@city
end
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "server=MCASYS13\\SQLEXPRESS;database=employee;user id=sa;pwd=admin123";
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "getempproc";
SqlParameter p = new SqlParameter("@city", SqlDbType.VarChar, 50);
p.Direction = ParameterDirection.Input;
p.Value = "Chennai";
cmd.Parameters.Add(p);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr[0].ToString());
Console.WriteLine(dr[1].ToString());
}
Console.Read();
}
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)