[Csharp] using System; using System. data; using System. configuration; using System. web; using System. web. security; using System. web. UI; using System. web. UI. webControls; using System. web. UI. webControls. webParts; using System. web. UI. htmlControls; using System. data. sqlClient; namespace Mysqlserver {// <summary> // summary of SqlServerDataBase /// </summary> public class SqlServerDataBase {private strin G strError = null; private int intCount = 0; public SqlServerDataBase () {// TODO: add the constructor logic // <summary> // The public method DBConn, return Database connection // </summary> /// <returns> </returns> public SqlConnection DBconn () {string strConn = "Server = (local); Database = GlobalMeetings; uid = sa; pwd = "; try {return new SqlConnection (strConn) ;}catch (Exception) {return null ;}} /// <summary> /// publish the attribute ErrorMessage and return an error Error message // </summary> public string ErrorMessage {get {return strError ;}} /// <summary> /// retrieve data from the database based on the query statement // </summary> /// <param name = "strSelect"> query statement </param> /// <param name = "SqlConn"> database connection </param> // <returns> If data exists, the DataSet object is returned, otherwise, null </returns> public DataSet Select (string SelectString, SqlConnection sqlConn) {strError = ""; SqlConnection conn; if (sqlConn = null) is returned) {conn = DBconn ();} els E {conn = sqlConn;} try {// if the current status of the database connection is closed, open the connection if (conn. state = ConnectionState. closed) {conn. open ();} SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter (); SqlCommand selectCommand = new SqlCommand (SelectString, conn); selectCommand. commandType = CommandType. text; mySqlDataAdapter. selectCommand = selectCommand; DataSet myDS = new DataSet (); mySqlDataAdapter. fill (myDS); return myDS;} ca Tch (Exception e) {strError = "data retrieval failed:" + e. Message; return null;} finally {if (conn. State! = ConnectionState. closed) {conn. close ();}}} /// <summary> /// Update the database /// </summary> /// <param name = "UpdateString"> Update SQL statement </param> /// <param name = "SqlConn"> database connection </param> // <returns> returns true after successful Update </returns> public bool Update (string UpdateString, sqlConnection SqlConn) {return udiDataBase (UpdateString, SqlConn );} /// <summary> /// delete data from the database /// </summary> /// <param name = "DeleteString"> Dele Te SQL statement </param> /// <param name = "SqlConn"> database connection </param> /// <returns> returns true If deletion is successful </returns> public bool delete (string DeleteString, sqlConnection SqlConn) {return udiDataBase (DeleteString, SqlConn );} /// <summary> /// Insert data into the database /// </summary> /// <param name = "InsertString"> Insert SQL statement </param> // /<param name = "SqlConn"> database connection </param> // <returns> returns true after successful insertion </returns> public bool Insert (string Inser TString, SqlConnection SqlConn) {return udiDataBase (InsertString, SqlConn );} /// <summary> /// update the database based on the SQL statement // </summary> /// <param name = "UDIString"> Update statement </param> // /<param name = "SqlConn"> database connection </param> // <returns> returns true if the update is successful </returns> public bool udiDataBase (string UDIString, sqlConnection SqlConn) {strError = ""; SqlConnection conn; if (SqlConn = null) {conn = DBconn ();} else {conn = S QlConn;} try {if (conn. state = ConnectionState. closed) {conn. open ();} SqlCommand cmd = new SqlCommand (UDIString, conn); cmd. commandType = CommandType. text; intCount = cmd. executeNonQuery (); return! (IntCount <1);} catch (Exception e) {strError = "failed to update database:" + e. Message; return false;} finally {if (conn. State! = ConnectionState. Closed) {conn. Close ();}}}}}