/ Published in: C#
Database connection class to be easily incorporated into any db based softwares, using SQLite 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class DatabaseConnection { private SQLiteConnection conn; private SQLiteCommand sqlCommand; private SQLiteDataAdapter DB; public DatabaseConnection() { } public SQLiteConnection Openconn() { if (conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken) { conn.Open(); } return conn; } public SQLiteConnection Closeconn() { if (conn.State == ConnectionState.Open) { conn.Close(); } return conn; } public void ExecuteQuery(string txtQuery) { try { cmd.Connection = Openconn(); cmd.CommandText = txtQuery; cmd.ExecuteNonQuery(); } catch (Exception Ex) { throw Ex; } finally { cmd = null; } } public DataSet returnDataSet(string txtQuery) { conn.Open(); sqlCommand = conn.CreateCommand(); DS.Reset(); DB.Fill(DS); conn.Close(); return (DS); } public DataTable returnDataTable(string txtQuery) { SQLiteDataAdapter adap; try { cmd.Connection = Openconn(); cmd.CommandText = txtQuery; adap.Fill(dt); return dt; } catch (Exception Ex) { throw Ex; } finally { cmd = null; } } public SQLiteDataReader returnDataReader(string txtQuery) { try { cmd.Connection = Openconn(); cmd.CommandText = txtQuery; SQLiteDataReader rd; rd = cmd.ExecuteReader(); return rd; } catch (Exception Ex) { throw Ex; } finally { cmd = null; } } }