0
Query excecution Using Stored Procedure
Posted by Rajendra Prasad Panchati
on
Monday, February 15, 2010
in
SQL Server
Here i'm using SQL Server as my database. So i needed 1)using System.Data; 2)using System.Data.SqlClient; namespaces.
try
{
String objConnectionString= ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection objSQLConnection = new SqlConnection(objConnectionString);
SqlCommand objSQLCommand = new SqlCommand();
objSQLCommand .Connection = objSQLConnection ;
objSQLCommand .CommandType = CommandType.StoredProcedure;
objSQLCommand .CommandText = "Your Stored Procedure name";
if(objSQLConnection .State==ConnectionState.Closed)
objSQLConnection .Open()
objSQLCommand .ExecuteNonQuery();
}
catch(Exception ex)
{
Throw ex;
}
finally
{
if(objSQLConnection .State==ConnectionState.Open)
objSQLConnection .Close()
}
try
{
String objConnectionString= ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection objSQLConnection = new SqlConnection(objConnectionString);
SqlCommand objSQLCommand = new SqlCommand();
objSQLCommand .Connection = objSQLConnection ;
objSQLCommand .CommandType = CommandType.StoredProcedure;
objSQLCommand .CommandText = "Your Stored Procedure name";
if(objSQLConnection .State==ConnectionState.Closed)
objSQLConnection .Open()
objSQLCommand .ExecuteNonQuery();
}
catch(Exception ex)
{
Throw ex;
}
finally
{
if(objSQLConnection .State==ConnectionState.Open)
objSQLConnection .Close()
}
More
Less