Home > Code > C# > Executing stored Procedure usign C#.NET

Executing stored Procedure usign C#.NET

by Thamil   on Dec 25, 2011   Category: C#   |  Views: 1175    |  Points: 25   |  Gold 



The below c# sample used to execute sql server stored procedure and retrieving the data by using SqlDataReader.

using System;
using System.Data;
using System.Data.SqlClient;

public void ExecuteStoredProc()
{
SqlConnection objCon = null;
SqlDataReader objRdr = null;
try
{
objCon = new SqlConnection("...CONNECTION STRING....");
objCon.Open();
SqlCommand cmd = new SqlCommand("Stored_Proc_Name", objCon);
cmd.CommandType = CommandType.StoredProcedure;
objRdr = cmd.ExecuteReader();
while (objRdr.Read())
{
Response.Write(objRdr["Emp_Name"].ToString() + "<BR>");
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
objCon.Close();
objRdr.Close();
}
}




Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts