M
mmorvant
I have made some functions to help with some of the more routine things
I do. I just wanted to see if they were "safe" for a production
setting?
public static System.Data.SqlClient.SqlConnection DbConnect()
{
System.Data.SqlClient.SqlConnection tConn = new
SqlConnection(strConn);
tConn.Open();
return tConn;
}
public static void ExecuteNonQuery(string strQuery)
{
SqlConnection tConn = DbConnect();
SqlCommand cmd = new SqlCommand(strQuery,tConn);
cmd.ExecuteNonQuery();
cmd.Dispose();
tConn.Close();
tConn.Dispose();
}
public static string ExecuteScalar(string strQuery)
{
string tString = "";
SqlConnection tConn = DbConnect();
SqlCommand cmd = new SqlCommand(strQuery,tConn);
tString = cmd.ExecuteScalar().ToString();
cmd.Dispose();
tConn.Close();
tConn.Dispose();
return tString;
}
public static SqlDataReader ExecuteReader(string strQuery)
{
SqlConnection drConn = DbConnect();
SqlCommand drCmd = new SqlCommand(strQuery,drConn);
return drCmd.ExecuteReader(CommandBehavior.CloseConnection);
}
Please excuse the poor wrapping....
I do. I just wanted to see if they were "safe" for a production
setting?
public static System.Data.SqlClient.SqlConnection DbConnect()
{
System.Data.SqlClient.SqlConnection tConn = new
SqlConnection(strConn);
tConn.Open();
return tConn;
}
public static void ExecuteNonQuery(string strQuery)
{
SqlConnection tConn = DbConnect();
SqlCommand cmd = new SqlCommand(strQuery,tConn);
cmd.ExecuteNonQuery();
cmd.Dispose();
tConn.Close();
tConn.Dispose();
}
public static string ExecuteScalar(string strQuery)
{
string tString = "";
SqlConnection tConn = DbConnect();
SqlCommand cmd = new SqlCommand(strQuery,tConn);
tString = cmd.ExecuteScalar().ToString();
cmd.Dispose();
tConn.Close();
tConn.Dispose();
return tString;
}
public static SqlDataReader ExecuteReader(string strQuery)
{
SqlConnection drConn = DbConnect();
SqlCommand drCmd = new SqlCommand(strQuery,drConn);
return drCmd.ExecuteReader(CommandBehavior.CloseConnection);
}
Please excuse the poor wrapping....