The source code is as follows:
Using system;using system.data;using system.data.oledb;using system.io;using system.windows.forms;namespace Test{ Class Database {public static bool Database_exists () {if (! File.exists (Application.startuppath + "\\DataBase.mdb")) {return false; } else {return true; }} public OleDbConnection get_conn () {try {string conn_string = ""; conn_string = "Data source= ' Database.mdb '; provider=microsoft.ace.oledb.12.0; "; OleDbConnection db_conn = new OleDbConnection (conn_string); Db_conn.open (); return db_conn; } catch (Exception e) {error.database_error_conn = E.message.tostring (); return null; }} public OleDbDataReader Select (string select_string) {TRy {if (get_conn () = = null) {return null; } OleDbCommand db_cmd = new OleDbCommand (select_string, Get_conn ()); OleDbDataReader db_reader = Db_cmd.executereader (); Db_reader.read (); return db_reader; } catch (Exception e) {error.database_error_select = E.message.tostring (); return null; }} public int action_the_sql (string sql_string) {try {if (Get _conn () = = null) {return 0; } OleDbCommand db_cmd = new OleDbCommand (sql_string, Get_conn ()); int line = Db_cmd.executenonquery (); return line; } catch (Exception e) {error.database_error_action_the_sql = E.message.tostring (); return 0; }} public DataSet GetDataSet (string sql_string, String tableName) {try { if (get_conn () = = null) {return null; } OleDbDataAdapter Adapter = new OleDbDataAdapter (sql_string, Get_conn ()); DataSet DS = new DataSet (); Adapter.fill (DS, tableName); return DS; } catch (Exception j) {error.database_error_getdataset = J.message.tostring (); return null; }} public string GetData (string sql_string) {try {if (Get_con N () = = null) {return null; } OleDbCommand db_cmd = new OleDbCommand (sql_string, Get_conn ()); String data = Convert.ToString (Db_cmd.executescalar ()); return data; } catch (Exception e) {error.database_error_action_the_sql = E.message.tostr ING (); return null; } } }}
The source code for the wrong (error) class It refers to IS as follows:
Namespace test{ class Error {public static string database_error_select; public static string Database_error_conn; public static string Database_error_action_the_sql; public static string Database_error_getdataset;} }
C # Homemade database operation class Code