class SqlHelper
{
public static SqlConnection conn; public static SqlConnection Open(string connStr)
{
if (!string.IsNullOrEmpty(connStr))
{
SqlConnection conn = new SqlConnection(connStr);
try
{
conn.Open();
return conn;
}
catch (Exception)
{
}
}
return null;
} public static bool Open(SqlConnection conn)
{
if (conn != null && conn.State != ConnectionState.Open)
{
try
{
conn.Open();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
return false;
} public static DataTable DB_Select(SqlConnection conn, string text, params SqlParameter[] parameters)
{
if (Open(conn))
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(text, conn);
da.Fill(dt);
return dt;
}
return null;
} public static void Close(SqlConnection conn)
{
if (conn != null && conn.State != ConnectionState.Closed)
conn.Close();
}
}