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