Using
System;
Using
System.collections;
Using
System.configuration;
Using
System.data;
Using
System.data.sqlclient;
Namespace
Data
...
{/ ** //// /// summary> public class cdata ... {public cdata () ... {/// TODO: Add constructor logic //} "here Database Connection Field "#Region" database connection field "/ ** //// /// join database field /// summary> protected static string ss_conn = configurationSettings.appsettings [" connectionstring "]; # endregion "Execute Database Basic Operation" #Region "Execute Database Basic Operation" / ** //// // / Operation SQL Statement (Insert, Update, Remove Data, New, Modify, Remove Table) /// Summary> /// Query SQL statement to be executed, string type string param> protected static void executesql (string strsql) ... {SQLConnection SCT = New SqlConnection; SS_CONN SQLCOMMAND SCM = New SQLCOMMAND (STRSQL, SCT); try ... {sct.open (); scm.executenonQuery ();} catch (system.data.sqlclient.sqlexception ex) ... {throw new exception (ex. Message);} finally ... {scm.dispose (); Sct.close ();}} # endregion "database data returns" #region "database data return" / ** //// ///////// Determine if the query data exists /// summary> /// To execute the query SQL statement, the string type String param> public static bool zexist (string strsql) ... {SQLCONNECTION SCT = New SqlConnection (SS_CONN); SQLCommand SCM = New Sqlcommand (strsql, SCT); TRY ... {SCT .Open (); sqldatareader sdr = scm.executeRead (); if (sdr.read ()) ... {return true;} else ... {returnaf false;}} catch (system.data.sqlclient.sqlexception EX ) ... {throw new exception;} finally ... {scm.dispose (); SCT.CLOSE ();}} / ** //// /// judgment query data Whether it exists, and returns the required value /// summary> /// To execute the SQL statement, the string type String param> public string returndatarader (String strsql) ... {SQLCONNECTION SCT = New SqlConnection (SS_CONN); SQLCOMMAND SCM = New Sqlcommand (strsql, SCT); Try ... {SCT.Open ();
SqlDataReader SDR = SCM.ExecuteReader (); if (SDR.Read ()) ... {Return SDR.GetValue (0) .tostring (). Trim ();} else ... {return "null";}} Catch (system.data.sqlclient.sqlexception ex) ... {throw new exception;} finally ... {scm.dispose (); Sct.close ();}} / ** //// / /// Get data view /// summary> /// param> /// returns> Public DataView ReturndataView (String Strsql). .. {SQLCONNECTION SCT = New SQLCONNECTION (SS_CONN); Try ... {SCT.Open (); SqlDataAdapter SDA = New SqlDataAdapter (STRSQL, SCT); DataSet DS = New DataSet (); SDA.FILL (DS); Return Ds.Tables [0] .defaultview;} catch (system.data.sqlclient.sqlexception ex) ... {throw new exception;} finally ... {sct.close ();}} / * * //// /// get DATAROW (a row of data in the table) /// summary> /// param> /// < / returns> public DataRow ReturnDataRow (string strsql) ... {SqlConnection sct = new SqlConnection (ss_conn); try ... {sct.Open (); SqlDataAdapter sda = new SqlDataAdapter (strsql, sct); DataSet ds = new DataSet (); SDA.FILL (DS) Return DS.Tables [0] .ROWS [0];} catch (system.data.sqlclient.sqlexception ex) ... {throw new exception;} finally ... {sct.close () ;}} / ** //// /// Get data view /// summary> /// param> /// returns > public DataSet ReturnDataSet (string strsql) ... {SqlConnection sct = new SqlConnection (ss_conn); try ... {sct.Open (); SqlDataAdapter sda = new SqlDataAdapter (strsql, sct); DataSet ds = new DataSet () SDA.FILL (DS); Return DS;} catch (system.data.sqlclient.sqlexception ex) ... {throw new exception;} finally ... {sct.close ();
}} # endregion}} TRACKBACK: http://tb.blog.9cbs.net/trackback.aspx?postid=451488