Monday, June 15, 2009

ADO.NET : Calling Store procedure

ADO.NET : Calling Store procedure

private void SpTest (id, string name)

{

SqlConnection sqlConn= new SqlConnection(_sqlConnString);

try

{

SqlCommand sqlCmd = new SqlCommand();

sqlCmd.CommandText = "sp_test";

sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Parameters.Add("id", SqlDbType.Int);

sqlCmd.Parameters.Add("name", SqlDbType.VarChar);

sqlCmd.Parameters[0].Value = id;

sqlCmd.Parameters[0].Direction = ParameterDirection.Input;

sqlCmd.Parameters[1].Value = name;

sqlCmd.Parameters[0].Direction = ParameterDirection.Input;

sqlCmd.Connection = sqlConn;

sqlConn.Open();

sqlCmd.ExecuteNonQuery();

}

catch (Exception exSp)

{

throw exSp;

}

finally

{

sqlConn.Close();

}

}

No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code