Last active
October 14, 2016 17:57
-
-
Save pipiscrew/b3413f365b549f2ef582a1d1fe846ccd to your computer and use it in GitHub Desktop.
C# dbase connections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.IO; | |
using System.Linq; | |
using System.Runtime.Serialization.Formatters.Binary; | |
using System.Windows.Forms; | |
namespace PipisCrew.Helpers | |
{ | |
static class General | |
{ | |
public static OdbcClass conn1; | |
public static ORACLEClass conn2; | |
public static SQLClass conn3; | |
public static SQLiteClass conn4; | |
//example of ^classes use - somewhere in the form : | |
///////////////////////////////////////////////////// | |
//SqlException x = null; | |
//General.conn3 = new SQLClass(the_connection_string, out x); | |
//if (x != null) | |
//{ | |
// MessageBox.Show("SQL Connection Error\r\n" + x.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); | |
// return; | |
//} | |
///////////////////////////////////////////////////// | |
#region " INPUTBOX " | |
public static DialogResult InputBox(string title, string promptText, ref string value) | |
{ | |
Form form = new Form(); | |
Label label = new Label(); | |
TextBox textBox = new TextBox(); | |
Button buttonOk = new Button(); | |
Button buttonCancel = new Button(); | |
form.Text = title; | |
label.Text = promptText; | |
textBox.Text = value; | |
buttonOk.Text = "OK"; | |
buttonCancel.Text = "Cancel"; | |
buttonOk.DialogResult = DialogResult.OK; | |
buttonCancel.DialogResult = DialogResult.Cancel; | |
label.SetBounds(9, 20, 372, 13); | |
textBox.SetBounds(12, 36, 372, 20); | |
buttonOk.SetBounds(228, 72, 75, 23); | |
buttonCancel.SetBounds(309, 72, 75, 23); | |
label.AutoSize = true; | |
textBox.Anchor = textBox.Anchor | AnchorStyles.Right; | |
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; | |
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; | |
form.ClientSize = new Size(396, 107); | |
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel }); | |
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height); | |
form.FormBorderStyle = FormBorderStyle.FixedDialog; | |
form.StartPosition = FormStartPosition.CenterScreen; | |
form.MinimizeBox = false; | |
form.MaximizeBox = false; | |
form.AcceptButton = buttonOk; | |
form.CancelButton = buttonCancel; | |
DialogResult dialogResult = form.ShowDialog(); | |
value = textBox.Text; | |
return dialogResult; | |
} | |
#endregion | |
#region " CLIPBOARD OPERATIONS " | |
public static void Copy2Clipboard(string val) | |
{ | |
try | |
{ | |
Clipboard.Clear(); | |
Clipboard.SetDataObject(val, true); | |
} | |
catch (Exception e) | |
{ | |
MessageBox.Show(e.Message, Application.ProductName); | |
} | |
} | |
public static string GetFromClipboard() | |
{ | |
try | |
{ | |
return Clipboard.GetText().Trim(); | |
} | |
catch (Exception e) | |
{ | |
MessageBox.Show(e.Message, Application.ProductName); | |
return ""; | |
} | |
} | |
#endregion | |
internal static void PointInsideFolder(string filepath) | |
{ | |
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() | |
{ | |
FileName = filepath, | |
UseShellExecute = true, | |
Verb = "open" | |
}); | |
} | |
#region " TREEVIEW SAVE/LOAD " | |
//http://stackoverflow.com/a/5868931 | |
public static void SaveTree(TreeView tree, string filename) | |
{ | |
using (Stream file = File.Open(filename, FileMode.Create)) | |
{ | |
BinaryFormatter bf = new BinaryFormatter(); | |
bf.Serialize(file, tree.Nodes.Cast<TreeNode>().ToList()); | |
} | |
} | |
public static void LoadTree(TreeView tree, Stream filename) | |
{ | |
BinaryFormatter bf = new BinaryFormatter(); | |
object obj = bf.Deserialize(filename); | |
TreeNode[] nodeList = (obj as IEnumerable<TreeNode>).ToArray(); | |
tree.Nodes.AddRange(nodeList); | |
} | |
#endregion | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.Data.Odbc; | |
using System.Windows.Forms; | |
namespace PipisCrew.Helpers | |
{ | |
class OdbcClass | |
{ | |
private OdbcConnection objConn; | |
private string m_ConnectionString; | |
//must exist at Control Panel\Administrative Tools\Data Sources (ODBC)\System DSN tab | |
//the connection string should be like "DSN=the_dns_name" | |
public OdbcClass(string ConnectionString, out OdbcException ExceptionObject) | |
{ | |
try | |
{ | |
m_ConnectionString = ConnectionString; | |
objConn = new OdbcConnection(ConnectionString); | |
objConn.Open(); | |
ExceptionObject = null; | |
} | |
catch (OdbcException ex) | |
{ | |
objConn = null; | |
ExceptionObject = ex; | |
} | |
} | |
public bool IsConnected | |
{ | |
get | |
{ | |
if (objConn == null | objConn.State != ConnectionState.Open) | |
{ | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
} | |
public string ConnectionString | |
{ | |
get { return m_ConnectionString; } | |
} | |
public OdbcDataAdapter GetAdapter(string Odbc) | |
{ | |
return new OdbcDataAdapter(Odbc, objConn); | |
} | |
public OdbcCommand GetCommand(string Query) | |
{ | |
return new OdbcCommand(Query, objConn); | |
} | |
public DataSet GetDATASET(string OdbcSTR) | |
{ | |
OdbcDataAdapter OdbcAD = new OdbcDataAdapter(); | |
DataSet OdbcSET = new DataSet(); | |
OdbcCommand Odbcco = new OdbcCommand(); | |
try | |
{ | |
Odbcco.CommandText = OdbcSTR; | |
Odbcco.Connection = objConn; | |
OdbcAD.SelectCommand = Odbcco; | |
OdbcAD.Fill(OdbcSET, "tabl"); | |
return OdbcSET; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OdbcClass - GetDATASET"); | |
return null; | |
} | |
finally | |
{ | |
Odbcco.Dispose(); | |
OdbcAD.Dispose(); | |
OdbcSET.Dispose(); | |
} | |
} | |
public DataSet GetDATASET2(string OdbcSTR, out string error) | |
{ | |
OdbcDataAdapter OdbcAD = new OdbcDataAdapter(); | |
DataSet OdbcSET = new DataSet(); | |
OdbcCommand Odbcco = new OdbcCommand(); | |
try | |
{ | |
Odbcco.CommandText = OdbcSTR; | |
Odbcco.Connection = objConn; | |
OdbcAD.SelectCommand = Odbcco; | |
OdbcAD.Fill(OdbcSET, "tabl"); | |
error = ""; | |
return OdbcSET; | |
} | |
catch (Exception ex) | |
{ | |
error = ex.Message; | |
return null; | |
} | |
finally | |
{ | |
Odbcco.Dispose(); | |
OdbcAD.Dispose(); | |
OdbcSET.Dispose(); | |
} | |
} | |
public OdbcDataReader GetDATAREADER(string OdbcSTR) | |
{ | |
OdbcDataReader Odbcread = null; | |
OdbcCommand Odbcco = new OdbcCommand(); | |
try | |
{ | |
Odbcco.Connection = objConn; | |
Odbcco.CommandText = OdbcSTR; | |
Odbcread = Odbcco.ExecuteReader(); | |
return Odbcread; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OdbcClass - GetDATAREADER"); | |
return null; | |
} | |
finally | |
{ | |
Odbcco.Dispose(); | |
//Odbcread.Close() | |
} | |
} | |
public DataTable GetDATATABLE(string OdbcSTR) | |
{ | |
OdbcDataAdapter OdbcAD = new OdbcDataAdapter(); | |
DataTable OdbcSET = new DataTable(); | |
OdbcCommand Odbcco = new OdbcCommand(); | |
try | |
{ | |
Odbcco.CommandText = OdbcSTR; | |
Odbcco.Connection = objConn; | |
OdbcAD.SelectCommand = Odbcco; | |
//OdbcAD.MissingSchemaAction = MissingSchemaAction.AddWithKey; | |
OdbcAD.Fill(OdbcSET); | |
return OdbcSET; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OdbcClass - GetDATASET"); | |
return null; | |
} | |
finally | |
{ | |
Odbcco.Dispose(); | |
OdbcAD.Dispose(); | |
OdbcSET.Dispose(); | |
} | |
} | |
public OdbcConnection GetConnection() | |
{ | |
return objConn; | |
} | |
public object ExecuteOdbcScalar(string OdbcSTR) | |
{ | |
OdbcCommand Odbcco = new OdbcCommand(); | |
try | |
{ | |
Odbcco.Connection = objConn; | |
Odbcco.CommandText = OdbcSTR; | |
return Odbcco.ExecuteScalar(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OdbcClass - ExecuteOdbcScalar"); | |
return ""; | |
} | |
finally | |
{ | |
Odbcco.Dispose(); | |
} | |
} | |
public int ExecuteNonQuery(string OdbcSTR) | |
{ | |
int functionReturnValue = 0; | |
OdbcCommand Odbcco = new OdbcCommand(); | |
try | |
{ | |
Odbcco.Connection = objConn; | |
Odbcco.CommandText = OdbcSTR; | |
return Odbcco.ExecuteNonQuery(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OdbcClass - ExecuteOdbc"); | |
functionReturnValue = 0; | |
} | |
finally | |
{ | |
Odbcco.Dispose(); | |
} | |
return functionReturnValue; | |
} | |
public int ExecuteNonQuery(string OdbcSTR, out OdbcException ErrReport) | |
{ | |
int functionReturnValue = 0; | |
OdbcCommand Odbcco = new OdbcCommand(); | |
ErrReport = null; | |
try | |
{ | |
Odbcco.Connection = objConn; | |
Odbcco.CommandText = OdbcSTR; | |
return Odbcco.ExecuteNonQuery(); | |
} | |
catch (OdbcException sEX) | |
{ | |
ErrReport = sEX; | |
functionReturnValue = 0; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OdbcClass - ExecuteOdbc"); | |
functionReturnValue = 0; | |
} | |
finally | |
{ | |
Odbcco.Dispose(); | |
} | |
return functionReturnValue; | |
} | |
public void Close() | |
{ | |
if ((objConn != null)) | |
{ | |
objConn.Close(); | |
objConn.Dispose(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.Data.OracleClient; | |
using System.Windows.Forms; | |
namespace PipisCrew.Helpers | |
{ | |
class ORACLEClass | |
{ | |
private OracleConnection objConn; | |
private string m_ConnectionString; | |
//the connection string should be like : | |
//string conn = "Data Source=(DESCRIPTION=(ADDRESS_LIST=" | |
// + "(ADDRESS=(PROTOCOL=TCP)(HOST=##server##)(PORT=##port##)))" | |
// + "(CONNECT_DATA=(SID=##sid##)));" | |
// + "User Id=##youruser##;Password=##yourpass##;"; | |
public ORACLEClass(string ConnectionString, out OracleException ExceptionObject) | |
{ | |
try | |
{ | |
m_ConnectionString = ConnectionString; | |
objConn = new OracleConnection(ConnectionString); | |
objConn.Open(); | |
ExceptionObject = null; | |
} | |
catch (OracleException ex) | |
{ | |
objConn = null; | |
ExceptionObject = ex; | |
} | |
} | |
public DataTable GetDATATABLE(string SQLSTR) | |
{ | |
OracleDataAdapter sqlAD = new OracleDataAdapter(); | |
DataTable sqlSET = new DataTable(); | |
OracleCommand sqlco = new OracleCommand(); | |
try | |
{ | |
sqlco.CommandText = SQLSTR; | |
sqlco.Connection = objConn; | |
sqlAD.SelectCommand = sqlco; | |
//sqlAD.MissingSchemaAction = MissingSchemaAction.AddWithKey; | |
sqlAD.Fill(sqlSET); | |
return sqlSET; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OracleClass - GetDATASET"); | |
return null; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
sqlAD.Dispose(); | |
sqlSET.Dispose(); | |
} | |
} | |
public object ExecuteSQLScalar(string SQLSTR) | |
{ | |
OracleCommand sqlco = new OracleCommand(); | |
try | |
{ | |
sqlco.Connection = objConn; | |
sqlco.CommandText = SQLSTR; | |
return sqlco.ExecuteScalar(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OracleClass - ExecuteSQLScalar"); | |
return ""; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
} | |
} | |
public OracleDataReader GetDATAREADER(string SQLiteSTR) | |
{ | |
OracleDataReader SQLiteread = null; | |
OracleCommand SQLiteco = new OracleCommand(); | |
try | |
{ | |
SQLiteco.Connection = objConn; | |
SQLiteco.CommandText = SQLiteSTR; | |
SQLiteread = SQLiteco.ExecuteReader(); | |
return SQLiteread; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "OracleClass - GetDATAREADER"); | |
return null; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
//SQLiteread.Close() | |
} | |
} | |
public void Close() | |
{ | |
if ((objConn != null)) | |
{ | |
objConn.Close(); | |
objConn.Dispose(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Windows.Forms; | |
namespace PipisCrew.Helpers | |
{ | |
class SQLClass | |
{ | |
private SqlConnection objConn; | |
private string m_ConnectionString; | |
//the connection string should be like : | |
//"data source=##server##;initial catalog=##dbase##;persist security info=True;Integrated Security=SSPI;applicationintent=readonly" | |
//"Data Source=##server##;Initial Catalog=##dbase##;User ID=##user##;Password=##password##" | |
public SQLClass(string ConnectionString, out SqlException ExceptionObject) | |
{ | |
try | |
{ | |
m_ConnectionString = ConnectionString; | |
objConn = new SqlConnection(ConnectionString); | |
objConn.Open(); | |
ExceptionObject = null; | |
} | |
catch (SqlException ex) | |
{ | |
objConn = null; | |
ExceptionObject = ex; | |
} | |
} | |
public bool IsConnected | |
{ | |
get | |
{ | |
if (objConn == null | objConn.State != ConnectionState.Open) | |
{ | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
} | |
public string ConnectionString | |
{ | |
get { return m_ConnectionString; } | |
} | |
public SqlDataAdapter GetAdapter(string sql) | |
{ | |
return new SqlDataAdapter(sql, objConn); | |
} | |
public SqlCommand GetCommand(string Query) | |
{ | |
return new SqlCommand(Query, objConn); | |
} | |
public DataSet GetDATASET(string SQLSTR) | |
{ | |
SqlDataAdapter sqlAD = new SqlDataAdapter(); | |
DataSet sqlSET = new DataSet(); | |
SqlCommand sqlco = new SqlCommand(); | |
try | |
{ | |
sqlco.CommandText = SQLSTR; | |
sqlco.Connection = objConn; | |
sqlAD.SelectCommand = sqlco; | |
sqlAD.Fill(sqlSET, "tabl"); | |
return sqlSET; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLClass - GetDATASET"); | |
return null; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
sqlAD.Dispose(); | |
sqlSET.Dispose(); | |
} | |
} | |
public DataSet GetDATASET2(string SQLSTR, out string error) | |
{ | |
SqlDataAdapter sqlAD = new SqlDataAdapter(); | |
DataSet sqlSET = new DataSet(); | |
SqlCommand sqlco = new SqlCommand(); | |
try | |
{ | |
sqlco.CommandText = SQLSTR; | |
sqlco.Connection = objConn; | |
sqlAD.SelectCommand = sqlco; | |
sqlAD.Fill(sqlSET, "tabl"); | |
error = ""; | |
return sqlSET; | |
} | |
catch (Exception ex) | |
{ | |
error = ex.Message; | |
return null; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
sqlAD.Dispose(); | |
sqlSET.Dispose(); | |
} | |
} | |
public SqlDataReader GetDATAREADER(string SQLSTR) | |
{ | |
SqlDataReader sqlread = null; | |
SqlCommand sqlco = new SqlCommand(); | |
try | |
{ | |
sqlco.Connection = objConn; | |
sqlco.CommandText = SQLSTR; | |
sqlread = sqlco.ExecuteReader(); | |
return sqlread; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLClass - GetDATAREADER"); | |
return null; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
//sqlread.Close() | |
} | |
} | |
public DataTable GetDATATABLE(string SQLSTR) | |
{ | |
SqlDataAdapter sqlAD = new SqlDataAdapter(); | |
DataTable sqlSET = new DataTable(); | |
SqlCommand sqlco = new SqlCommand(); | |
try | |
{ | |
sqlco.CommandText = SQLSTR; | |
sqlco.Connection = objConn; | |
sqlAD.SelectCommand = sqlco; | |
//sqlAD.MissingSchemaAction = MissingSchemaAction.AddWithKey; | |
sqlAD.Fill(sqlSET); | |
return sqlSET; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLClass - GetDATASET"); | |
return null; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
sqlAD.Dispose(); | |
sqlSET.Dispose(); | |
} | |
} | |
public SqlConnection GetConnection() | |
{ | |
return objConn; | |
} | |
public object ExecuteSQLScalar(string SQLSTR) | |
{ | |
SqlCommand sqlco = new SqlCommand(); | |
try | |
{ | |
sqlco.Connection = objConn; | |
sqlco.CommandText = SQLSTR; | |
return sqlco.ExecuteScalar(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLClass - ExecuteSQLScalar"); | |
return ""; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
} | |
} | |
public int ExecuteNonQuery(string SQLSTR) | |
{ | |
int functionReturnValue = 0; | |
SqlCommand sqlco = new SqlCommand(); | |
try | |
{ | |
sqlco.Connection = objConn; | |
sqlco.CommandText = SQLSTR; | |
return sqlco.ExecuteNonQuery(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLClass - ExecuteSQL"); | |
functionReturnValue = 0; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
} | |
return functionReturnValue; | |
} | |
public int ExecuteNonQuery(string SQLSTR, out SqlException ErrReport) | |
{ | |
int functionReturnValue = 0; | |
SqlCommand sqlco = new SqlCommand(); | |
ErrReport = null; | |
try | |
{ | |
sqlco.Connection = objConn; | |
sqlco.CommandText = SQLSTR; | |
return sqlco.ExecuteNonQuery(); | |
} | |
catch (SqlException sEX) | |
{ | |
ErrReport = sEX; | |
functionReturnValue = 0; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLClass - ExecuteSQL"); | |
functionReturnValue = 0; | |
} | |
finally | |
{ | |
sqlco.Dispose(); | |
} | |
return functionReturnValue; | |
} | |
public void Close() | |
{ | |
if ((objConn != null)) | |
{ | |
objConn.Close(); | |
objConn.Dispose(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Finisar.SQLite; | |
using System; | |
using System.Data; | |
using System.Windows.Forms; | |
namespace PipisCrew.Helpers | |
{ | |
internal class SQLiteClass | |
{ | |
private SQLiteConnection objConn; | |
private string m_ConnectionString; | |
//the connection string should be like : | |
//string isnew=";New=True"; | |
//if (File.Exists(Application.StartupPath + "\\dbase.db3")) | |
// isnew = ";New=False"; | |
//my_conn = new SQLiteClass("Data Source=dbase.db3;Version=3;UTF8Encoding=True" + isnew); | |
public SQLiteClass(string ConnectionString) | |
{ | |
try | |
{ | |
m_ConnectionString = ConnectionString; | |
objConn = new SQLiteConnection(ConnectionString); | |
objConn.Open(); | |
} | |
catch (SQLiteException ex) | |
{ | |
objConn = null; | |
} | |
} | |
public bool IsConnected | |
{ | |
get | |
{ | |
if (objConn == null | objConn.State != ConnectionState.Open) | |
{ | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
} | |
public string ConnectionString | |
{ | |
get { return m_ConnectionString; } | |
} | |
public SQLiteDataAdapter GetAdapter(string SQLite) | |
{ | |
return new SQLiteDataAdapter(SQLite, objConn); | |
} | |
public SQLiteCommand GetCommand(string Query) | |
{ | |
return new SQLiteCommand(Query, objConn); | |
} | |
public DataSet GetDATASET(string SQLiteSTR) | |
{ | |
SQLiteDataAdapter SQLiteAD = new SQLiteDataAdapter(); | |
DataSet SQLiteSET = new DataSet(); | |
SQLiteCommand SQLiteco = new SQLiteCommand(); | |
try | |
{ | |
SQLiteco.CommandText = SQLiteSTR; | |
SQLiteco.Connection = objConn; | |
SQLiteAD.SelectCommand = SQLiteco; | |
SQLiteAD.Fill(SQLiteSET, "tabl"); | |
return SQLiteSET; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLiteClass - GetDATASET"); | |
return null; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
SQLiteAD.Dispose(); | |
SQLiteSET.Dispose(); | |
} | |
} | |
public DataSet GetDATASET2(string SQLiteSTR, out string error) | |
{ | |
SQLiteDataAdapter SQLiteAD = new SQLiteDataAdapter(); | |
DataSet SQLiteSET = new DataSet(); | |
SQLiteCommand SQLiteco = new SQLiteCommand(); | |
try | |
{ | |
SQLiteco.CommandText = SQLiteSTR; | |
SQLiteco.Connection = objConn; | |
SQLiteAD.SelectCommand = SQLiteco; | |
SQLiteAD.Fill(SQLiteSET, "tabl"); | |
error = ""; | |
return SQLiteSET; | |
} | |
catch (Exception ex) | |
{ | |
error = ex.Message; | |
return null; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
SQLiteAD.Dispose(); | |
SQLiteSET.Dispose(); | |
} | |
} | |
public SQLiteDataReader GetDATAREADER(string SQLiteSTR) | |
{ | |
SQLiteDataReader SQLiteread = null; | |
SQLiteCommand SQLiteco = new SQLiteCommand(); | |
try | |
{ | |
SQLiteco.Connection = objConn; | |
SQLiteco.CommandText = SQLiteSTR; | |
SQLiteread = SQLiteco.ExecuteReader(); | |
return SQLiteread; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLiteClass - GetDATAREADER"); | |
return null; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
//SQLiteread.Close() | |
} | |
} | |
public DataTable GetDATATABLE(string SQLiteSTR) | |
{ | |
SQLiteDataAdapter SQLiteAD = new SQLiteDataAdapter(); | |
DataTable SQLiteSET = new DataTable(); | |
SQLiteCommand SQLiteco = new SQLiteCommand(); | |
try | |
{ | |
SQLiteco.CommandText = SQLiteSTR; | |
SQLiteco.Connection = objConn; | |
SQLiteAD.SelectCommand = SQLiteco; | |
//SQLiteAD.MissingSchemaAction = MissingSchemaAction.AddWithKey; | |
SQLiteAD.Fill(SQLiteSET); | |
return SQLiteSET; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLiteClass - GetDATASET"); | |
return null; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
SQLiteAD.Dispose(); | |
SQLiteSET.Dispose(); | |
} | |
} | |
public SQLiteConnection GetConnection() | |
{ | |
return objConn; | |
} | |
public object ExecuteSQLiteScalar(string SQLiteSTR) | |
{ | |
SQLiteCommand SQLiteco = new SQLiteCommand(); | |
try | |
{ | |
SQLiteco.Connection = objConn; | |
SQLiteco.CommandText = SQLiteSTR; | |
return SQLiteco.ExecuteScalar(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLiteClass - ExecuteSQLiteScalar"); | |
return ""; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
} | |
} | |
public int ExecuteNonQuery(string SQLiteSTR) | |
{ | |
int functionReturnValue = 0; | |
SQLiteCommand SQLiteco = new SQLiteCommand(); | |
try | |
{ | |
SQLiteco.Connection = objConn; | |
SQLiteco.CommandText = SQLiteSTR; | |
return SQLiteco.ExecuteNonQuery(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLiteClass - ExecuteSQLite"); | |
functionReturnValue = 0; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
} | |
return functionReturnValue; | |
} | |
public int ExecuteNonQuery(string SQLiteSTR, out SQLiteException ErrReport) | |
{ | |
int functionReturnValue = 0; | |
SQLiteCommand SQLiteco = new SQLiteCommand(); | |
ErrReport = null; | |
try | |
{ | |
SQLiteco.Connection = objConn; | |
SQLiteco.CommandText = SQLiteSTR; | |
return SQLiteco.ExecuteNonQuery(); | |
} | |
catch (SQLiteException sEX) | |
{ | |
ErrReport = sEX; | |
functionReturnValue = 0; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "SQLiteClass - ExecuteSQLite"); | |
functionReturnValue = 0; | |
} | |
finally | |
{ | |
SQLiteco.Dispose(); | |
} | |
return functionReturnValue; | |
} | |
public void Close() | |
{ | |
if ((objConn != null)) | |
{ | |
objConn.Close(); | |
objConn.Dispose(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment