Regarding using the SQL Server stored procedure... What is the best way (Prefferd) to use, put all sql commnads as a stored procedure, and when they are needed just to call the stored procedure (View code 1)? or just to put a complex sql syntax - commnads
- in a stored procedure, and all other simple sql commnads (Like: select * from Table1) to call as below (Code 2):
Code 1:
using (SqlConnection conn = new SqlConnection(Tools.GeneralConnectionString))
{
SqlCommand cmd = new SqlCommand("MyStoredProcedure", conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch
{
conn.Close();
}
}
Code 2:
using (SqlConnection conn = new SqlConnection(Tools.GeneralConnectionString))
{
SqlCommand cmd = new SqlCommand("select * from Table1", conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch
{
conn.Close();
}
}
Bader
Member
10 Points
84 Posts
Asp.net and SQL server - Stored procedure
May 02, 2012 11:10 AM|LINK
Hi,
Regarding using the SQL Server stored procedure... What is the best way (Prefferd) to use, put all sql commnads as a stored procedure, and when they are needed just to call the stored procedure (View code 1)? or just to put a complex sql syntax - commnads - in a stored procedure, and all other simple sql commnads (Like: select * from Table1) to call as below (Code 2):
Code 1:
using (SqlConnection conn = new SqlConnection(Tools.GeneralConnectionString)) { SqlCommand cmd = new SqlCommand("MyStoredProcedure", conn); try { conn.Open(); cmd.ExecuteNonQuery(); } catch { conn.Close(); } }Code 2:
using (SqlConnection conn = new SqlConnection(Tools.GeneralConnectionString)) { SqlCommand cmd = new SqlCommand("select * from Table1", conn); try { conn.Open(); cmd.ExecuteNonQuery(); } catch { conn.Close(); } }Regards,
Bader