A class that implements adds, modifies, deletes records

xiaoxiao2021-03-17  208

Using

System;

Using

System.collections;

Using

System.configuration;

Using

System.data;

Using

System.data.sqlclient;

Namespace

Data

...

{/ ** ////

/// public class cdata ... {public cdata () ... {/// TODO: Add constructor logic //} "here Database Connection Field "#Region" database connection field "/ ** //// /// join database field /// 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) /// /// Query SQL statement to be executed, string type string 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 /// /// To execute the query SQL statement, the string type String 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 /// /// To execute the SQL statement, the string type String 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 /// /// /// 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) /// /// /// < / 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 /// /// /// 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

转载请注明原文地址:https://www.9cbs.com/read-129695.html

New Post(0)