You are good, and you will be able to develop a system with .NET in this happily. I have made some satisfied packages. Please give some opinions. If you don't have a lot of time, there is not much time, I have to use the source Published in the form of code, please forgive me. There are related codes and comments, please download it yourself (Goto)
/ *********************************** * filename: wddb.cs * target: Processing Access Database Problem * Author: baihao * Createdate: 03/02/19 * lastmodify: 03/04/09 * history: * * *************************** ************* * /
Using system; using system.data.sqlclient; using wonder.sysconsole;
Namespace Wonder.Web.Data {/// /// WDDB summary description. /// summary> public class dbObject {
private const string CONNNECT_STRING = "data source = 172.16.36.222; initial catalog = RemoteEdu;" "persist security info = False; user id = sa; password = 1234567890;" "packet size = 4096"; private string m_sErrorMessage = null ;
Protected SqlConnection Connection; // Protects connection private string connectionsTRING; // Private connection string private const string def_table = "table1";
Private sqlcommand command = new SQLCOMMAND ();
/// /// a parameterized constructor, IT allows us to take a connection /// String as a constructor argument, automatically instantiarating /// a new connection. /// summary> /// Connection String to the associated database param> public dbObject (string newConnectionString) {connectionString = newConnectionString; Connection = new SqlConnection (connectionString); command.Connection = Connection;
}
public DbObject () //: base (/ * (SQLConnString.IniReadValue ( "catalog") == "") CONNNECT_STRING: * / SQLConnString.GetConnStr ()?) {connectionString = CONNNECT_STRING; Connection = new SqlConnection (connectionString); command .Connection = connection; // // TODO: Add constructor logic //} /// /// /////// SUMMARY> /// param> /// returns> public object sendstr (string str) {if (str == null) Return dbnull.Value; else return str;}
/// /// Transfer Date type parameter to SQLCommand /// ///// param> /// returns> public object senddate (DATETIME DT) {IF (dt.ticks == 0) Return DBNULL.VALUE; Else Return Dt;}
/// /// Transfer characteristic data to SQLCommand /// / summary> /// param> /// returns> public Object Sendchar (CHAR C) {IF (c == '/ 0') Return DBNULL.VALUE; Else Return C;} /// /// Transfer GUID type data to SQLCommand /// summary> // / param> /// returns> public object sendguid (guid c) {if (c == guid.empty) Return dbnull.Value; else return c; /// /// acquisition error Description /// summary> /// returns> public string getLastError () {return m_SerrorMessage;}
/// /// Clear the properties of the ERR object. /// summary> public void errclear () {m_serrorMessage = "";
/// /// Protected property that exposes the connection string /// to inheriting classes Read-Only /// summary> protected string ConnectionString {get {return connectionString;}}.. /// /// protected string /// TO inheriting classes. Read-only. /// summary> protected sqlcommand command {get {returnire;}}
/// /// Open /// summary> public void openconnect () {if (connection.State! = connectionState.closed) Connection.Close (); connection.open ();
/// /// Turns the connection, mainly using ////////////////////////////////>.State! = ConnectionsTate.Closed) Connection.Close ();}
/// // / execute the specified sql statement /// (ex: merinfo where userid = 'baihao'; ")) /// ** Need to turn on / off ** /// < / summary> public void execnoopen (string ssql) {command.commandtext = ssql; command.commandtype = commandType.text; command.executenon query ()
/// /// Execute Query statement, return DataReader /// ** Since DataRead is still queried, no disconnection, please pay attention ** // (EX: (Query " From memberinfo ")))) /// Do not need to open the connection, but need to close /// summary> /// Query statement param> /// a newly instantiated SqlDataReader Object RETURns> Public SqlDataReader Query (SQLDATAREADER RETURNREADER; TRY {OpenConnect ();
Command.commandType = commandType.text; command.commandtext = ssql;
ReturnReader = Command.executeReader (); //connection.close ();} catch (exception e) {m_serrorMessage = E.MESSAGE; RETURN NULL;} Return ReturnReader;
/// /// execute the SQL statement and return the query result, return a DataSet /// (ex: FillDataSet ("S: FillDataSet (" Select * from memberinfo ") /// // /// / Close connection /// // summary> /// SQL statement to execute param> /// returns> public dataset fixdataset (string ssql) {Return FillDataSet (SSQL, DEF_TABLE);} /// // / Execute SQL statement and return query results /// (ex: filldataset ("SELECT * from memberinfo", "memberinfo") /// does not need to open / Turn off /// summary> /// SQL statement to be executed param> /// Name in DataSet param > /// returns> PUBLIC DATASET FILDATASET (STRING SSQL, String Stable) {DataSet DataSet; Try {Dataset = New DataSet (); OpenConnect ();
Sqldataadapter sqlda = new sqldataadapter (); sqlda.selectcommand = command; command.commandtext = ssql; command.commandtype = commandType.Text;
Int nrows = sqlda.fill (Dataset, Stable);
IF (nROWS == 0) Dataset = null;} catch (sqlexception e) {m_serrorMessage = E.MESSAGE; RETURN NULL;
} Return DataSet;
/// /// Execute SQL statement and return query results /// (EX: FillDataSet (DS, "Select * from MemberInfo", "MemberInfo")) // Add Table // / Do not need to open / close connections /// summary> /// already existing DataSet, add table param> /// To execute SQL statement param> /// Returned DataSet "Name" Name param> /// returns> Public Bool FillDataSet (Ref DataSet DS, String SSQL, String sTable) {bool bRe = true; try {openConnect (); SqlDataAdapter sqlDA = new SqlDataAdapter (); sqlDA.SelectCommand = command; command.CommandText = sSql; command.CommandType = CommandType.Text;
Int nrows = sqlda.fill (DS, stable);
IF (nROWS == 0) BRE = false;} catch (sqlexception e) {m_serrorMessage = E.MESSAGE; RETURN FALSE;}
Return BRE;} /// /// execute the query, and return the first column of the first row of the result, ignore other rows and columns. /// ("Se: getfirstcolumn (" Select UserName from Meo ')) /// No Turmmary> //// summary> /// < / param> /// returns> public object getfirstcolumn (string ssql) {Try {Object ORE; OpenConnect (); command.commandtype = commandType.text; command.commandtext = ssql;
ORE = command.executescalar (); closeconnect ();
Return Ore;} catch (exception e) {m_serrorMessage = E.MESSAGE; RETURN NULL;}}
/// /// Execute the query, and return the results of the first column of the integer type, ignore other rows and columns. /// ("S:" "Select Count (*) from MemberInfo") /// No need to open / close connections /// summary> /// param> /// Returns -1, indicating unsuccessful, otherwise successfully returns> public int executeScalar (String SSQL) {Try {Int IRE; OpenConnect (); command.commandtype = commandType.Text; command.commandtext = ssql IRE = (int) Command.executescalar (); CloseConnect ();
Return IRE;} catch (exception e) {m_serrorMessage = E.MESSAGE; RETURN-1;}}
/// // / / ("delete Memberinfo where userid = 'baihao';") //// /// summary> /// param> public void exec (String SSQL) {Try {OpenConnect (); command.commandtype = commandType.Text; command.commandtext = ssql;
Command.executenonQuery (); CloseConnect ();} catch (exception e) {m_serrorMessage = E.MESSAGE;}}}
/// /// Package SqlDataReader, mainly processing dbnull /// summary> public class wdread {
public const byte NULL_INT = 0; public const string NULL_STR = ""; public static DateTime NULL_DATE = new DateTime (1,1,1); public const char NULL_CHAR = '/ 0'; public static Guid NULL_GUID = Guid.Empty; / // /// /// summary> public sqldataareader m_read = null;
/// /// Structure /// ///// param> public wdread (SqlDataReader Read) {m_read = read;} /// /// read a record /// summary> /// returns> public bool read () {return m_read.read ();} /// /// get a character String type /// summary> /// field name param> /// field value or null_str returns> public string gstring (String item) {IF ( m_read.isdbnull (m_read.getordinal (item))) Return Null_Str; Else Return M_Read.getstring (m_read.getordinal (item));}
/// /// acquired integer type /// summary> /// field name param> /// field value or null returns> Public int Gint (String Item) {if (m_read.isdbnull (m_read.getordinal (item))) Return Null_INT; Else Return M_Read.GetInt32 (M_Read.Getordinal (item));}
Public INT16 GWORD (STRING ITEM) {if (m_read.isdbnull (m_read.getrdinal (item))) Return Null_INT; Else Return M_Read.GetInt16 (M_Read.GetRinal (Item));
/// /// acquisition date type /// summary> /// field name param> /// field value or null_date returns> Public DateTime gdate (String item) {if (m_read.isdbnull (m_read.getrdinal (item))) Return Null_Date; else return m_read.getdatetime (m_read.getordinal (item));}
/// /// acquired byte type /// / summary> /// field name param> /// field value or null_int returns> Public Byte Gbyte (String Item) {IF (m_read.getbnull (m_read.getrdinal (item))) Return Null_INT; Else Return M_Read.getbyte (m_read.getordinal (item));} /// /// Boolean Type /// / summary> /// field name param> /// field value or null_int returns> public bool gbool (string item) {IF ( m_read.isdbnull (m_read.getordinal (item))) Return False; Else Return M_Read.getBoolean (M_Read.Getordinal (Item)); // (1 == m_read.getbyte (m_read.getordinal (item));}
/// /// gets char type /// summary> /// field name param> /// field value or null_int returns> Public char gchar (String Item) {if (m_read.isdbnull (m_read.getordinal (item))) Return Null_Char; Else Return Convert.TOCHAR (M_Read [item]);}
/// /// gets decimal type /// / summary> /// field name param> /// field value or null_int returns> Public Decimal GDEC (String Item) {if (m_read.isdbnull (m_read.getrdinal (item))) Return Null_INT; Else Return M_Read.getDecimal (m_read.getordinal (item));}
/// /// gets a GUID type /// //// field name param> /// field value or null_guid returns> Public Guid Gguid (String Item) {if (m_read.isdbnull (m_read.getrdinal (item))) Return Null_GUID; Else {Return M_Read.getGUID (m_read.getordinal (item));}}
/// /// gets the specified READ string /// summary> /// param> /// PARAM> /// return sqlic static string Gstr (SqlDataReader Read, INT ITEM) {if (read.read ()) {if (read.isdbnull (item)) Return Null; Else Return READ.GETSTRING (item);} else return null;
/// /// gets the specified READ string /// summary> /// param> /// Param> /// returns> public static string gstr (SqlDataReader Read, String Item) {if (read.iead ()) {if (read.isdbnull (item)) Return NULL; Else Return READ.GETSTSTRING (Read.Getordinal (Item));
} Else return null;}}}