get data from sql server db
is that a good practice?
public static void GetToolData(int TD_ID,out string pageH1)
{
using (SqlConnection con = Util.GetConnection())
{
con.Open();
GetToolData(con,TD_ID, out pageH1);
}
}
internal static void GetToolData(SqlConnection con, int TD_ID, out string pageH1)
{
using (SqlCommand cmd = new SqlCommand("usp_GetToolData", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@TD_ID", SqlDbType.Int).Value = TD_ID;
cmd.Parameters.Add("@TD_Name", SqlDbType.NVarChar,50).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
pageH1 = Convert.ToString(开发者_StackOverflow社区cmd.Parameters["@TD_Name"].Value);
}
}
or maybe there is better way to do that?
As long as, when you're calling GetToolData(), you keep your connection in a using this should be fine.
精彩评论