/*/' \/'. . .‘ : `. `. \\.‘ , `.` `. `. ,___/|\. `. : . \, .‘. / ‘ ‘\ , ‘ .\ . \_.~ _; ; \/‘. `\ ..._`. : /.. .. / /‘ _._ \. ~. ' ' \:/'. ' @ ` .---. `. .‘ : ' @ '. \. / ./`.. _./ ~ . :\ `. __ .‘ /(\ .....) . '/'. /‘‘‘\ .‘ `. / \ : ;‘ .‘ ..:.‘ ; `\; : : : : .‘ : ; :: `\. `\. ; : \.‘ " ‘ ; `. `. \/S. / `. .‘ ` . `. `\ `. ; /‘ ;___ ; `. `. `. ` ; ;:__..‘ `. `. `. : ': _. ' .‘ ; : `. `. . \x./-'--...../'; : `. .. -:.. -' (: '---'. `; : `. `,.. : : `. `. `.___; `. `. `. `; '-., ' goddess bless never bug*/public static class SQLHelper {private static SqlConnection Con; private static SqlCommand cmd; private static DataTable DT; private static DataSet DS; private Static SqlDataAdapter da; private static string sqlstr; private static void SQLHelper () {sqlstr = ""; }///<summary>///execute an SQL statement that returns the first value of the first row///</summary>//<param name= "SQL" ;</param>//<returns></returns> public static Object Getfirstvalue (String sql) { using (Con = new SqlConnection (sqlstr)) {Con.open (); cmd = new SqlCommand (sql, Con); return CMD. ExecuteScalar (); }}///<summary>///execute an SQL statement that returns the number of rows affected///</summary><param name= "SQL" ></param>///<returns></returns> public static int Getnonquery (String sql) {using (Con = new SqlConnection (sqlstr)) {Con.open (); cmd = new SqlCommand (sql, Con); return CMD. ExecuteNonQuery (); }}///<summary>///Offline mode populate DataTable and return, data can be used this method///</summary>//<p Aram name= "SQL" ></param>///<returns></returns> public static DataTable Getdatatablea ( String sql) {using (Con = new SqlConnection (sqlstr)) {da = new sqldataadapte R (SQL, Con); DT = new DataTable (); Da. Fill (DT); return DT; }}///<summary>///based on SQL, populate DataTable and return. You can use this method when you have more data.//</summary>//<param name= "SQL" ></param>//<returns></returns> public static DataTable Getdatatableb (String sql) {using (Con = new Sqlco Nnection (SQLSTR)) {Con.open (); cmd = new SqlCommand (sql, Con); DT = new DataTable (); SqlDataReader reader = cmd. ExecuteReader (); Dt. Load (reader); Con.close (); return DT; }}///<summary>///Incoming SQL statement set, return a DataSet///</summary>//<param Nam E= "Sqllist" ></param>///<returns></returns> public static DataSet GetDataSet (list<s Tring> sqllist) {using (Con = new SqlConnection (sqlstr)) {Con.open (); ds = new DataSet (); foreach (string C in sqllist) {cmd = new SqlCommand (c, Con); DT = new DataTable (); SqldatareaDer reader = cmd. ExecuteReader (); Dt. Load (reader); Ds. Tables.add (DT); } con.close (); return DS; }}////<summary> Execute multiple SQL statements in a transaction///</summary>//<param name= "list "></param>///<returns></returns> public static bool Execsqlslist (list<string> l IST) {using (Con = new SqlConnection (sqlstr)) {Con.open (); SqlTransaction tran = Con.begintransaction (); try {foreach (String sql in list) {cmd = new SqlCommand (SQL, Con); Cmd. ExecuteNonQuery (); } tran.commit (); Con.close (); return true; } catch {TRan. Rollback (); return false; } finally {con.close (); Con.dispose (); }}}///<summary> execute a stored procedure with no parameters, return datable//< ;/summary>//<param name= "StoredProcedureName" ></param>///<returns></returns> public static DataTable Getdatatablebystoredprocedure (string storedprocedurename) {using (Con = New SqlConnection (SQLSTR)) {Con.open (); cmd = new SqlCommand (); Cmd.commandtext = StoredProcedureName; Cmd.commandtype = CommandType.StoredProcedure; DT = new DataTable (); Dt. Load (cmd. ExecuteReader ()); return DT; } } }
Spare ~
Write your own public class to manipulate SQL