Thanks, nice article.
"And I'm sorry if someone may ask for tungDbDriver.dll inside the ZIP file. I lost that assembly code." => Here's the source produced with .NET Reflector[^]
Hope this is of any help for anyone.
namespace tungComponents.tungDbDriver
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Xml;
using System.Data.OracleClient;
using System.Data.OleDb;
public class DriverSqlServer
{
private SqlDataAdapter DataAdapter;
private string itsConnStr;
private SqlConnection SqlConn;
public DriverSqlServer(string SQLSERVER_SERVER, string SQLSERVER_USER, string SQLSERVER_PASSWORD, string SQLSERVER_DB)
{
this.itsConnStr = new clsConnStr().fMakeConnStr_SqlServer(SQLSERVER_SERVER, SQLSERVER_USER, SQLSERVER_PASSWORD, SQLSERVER_DB);
this.SqlConn = new SqlConnection();
this.DataAdapter = new SqlDataAdapter();
this.DataAdapter.SelectCommand = new SqlCommand("", this.SqlConn);
this.SqlConn.ConnectionString = this.itsConnStr;
this.SqlConn.Open();
}
public DriverSqlServer(string SQLSERVER_SERVER, string SQLSERVER_PORT, string SQLSERVER_USER, string SQLSERVER_PASSWORD, string SQLSERVER_DB)
{
this.itsConnStr = new clsConnStr().fMakeConnStr_SqlServer(SQLSERVER_SERVER, SQLSERVER_PORT, SQLSERVER_USER, SQLSERVER_PASSWORD, SQLSERVER_DB);
this.SqlConn = new SqlConnection();
this.DataAdapter = new SqlDataAdapter();
this.DataAdapter.SelectCommand = new SqlCommand("", this.SqlConn);
this.SqlConn.ConnectionString = this.itsConnStr;
this.SqlConn.Open();
}
public void fClose()
{
this.SqlConn.Close();
}
public int fExecuteNonQuery(SqlCommand sqlCommand)
{
sqlCommand.Connection = this.SqlConn;
return sqlCommand.ExecuteNonQuery();
}
public int fExecuteNonQuery(string query)
{
SqlCommand command = new SqlCommand(query, this.SqlConn);
return command.ExecuteNonQuery();
}
public SqlDataReader fExecuteReader(SqlCommand sqlCommand)
{
sqlCommand.Connection = this.SqlConn;
return sqlCommand.ExecuteReader();
}
public SqlDataReader fExecuteReader(string query)
{
SqlCommand command = new SqlCommand(query, this.SqlConn);
return command.ExecuteReader();
}
public object fExecuteScalar(SqlCommand sqlCommand)
{
sqlCommand.Connection = this.SqlConn;
return sqlCommand.ExecuteScalar();
}
public object fExecuteScalar(string query)
{
SqlCommand command = new SqlCommand(query, this.SqlConn);
return command.ExecuteScalar();
}
public XmlReader fExecuteXmlReader(SqlCommand sqlCommand)
{
sqlCommand.Connection = this.SqlConn;
return sqlCommand.ExecuteXmlReader();
}
public XmlReader fExecuteXmlReader(string query)
{
SqlCommand command = new SqlCommand(query, this.SqlConn);
return command.ExecuteXmlReader();
}
public int fSelectAndFillDataSet(string query, DataSet dataset)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset);
}
public int fSelectAndFillDataSet(string query, DataSet dataset, string srcTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset, srcTable);
}
public int fSelectAndFillDataSet(string query, DataSet dataset, int startRecord, int maxRecords, string srcTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset, startRecord, maxRecords, srcTable);
}
public int fSelectAndFillDataTable(string query, DataTable dataTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataTable);
}
public void fSelectAndFillWebDataGrid(string query, DataGrid dataGrid)
{
DataSet dataset = new DataSet();
this.fSelectAndFillDataSet(query, dataset);
dataGrid.DataSource = dataset;
dataGrid.DataBind();
}
public void fSelectAndFillWinFormDataGrid(string query, DataGrid dataGrid)
{
DataSet dataset = new DataSet();
this.fSelectAndFillDataSet(query, dataset, "Items");
dataGrid.SetDataBinding(dataset, "Items");
dataGrid.Refresh();
}
}
public class DriverOracle
{
private OracleDataAdapter DataAdapter;
private string itsConnStr;
private OracleConnection OracleConn;
public DriverOracle(string ORACLE_USER, string ORACLE_PASSWORD, string ORACLE_DB)
{
this.itsConnStr = new clsConnStr().fMakeConnStr_Oracle(ORACLE_USER, ORACLE_PASSWORD, ORACLE_DB);
this.OracleConn = new OracleConnection();
this.DataAdapter = new OracleDataAdapter();
this.DataAdapter.SelectCommand = new OracleCommand("", this.OracleConn);
this.OracleConn.ConnectionString = this.itsConnStr;
this.OracleConn.Open();
}
public void fClose()
{
this.OracleConn.Close();
}
public object fExecuteExecuteOracleScalar(string query)
{
OracleCommand command = new OracleCommand(query, this.OracleConn);
return command.ExecuteOracleScalar();
}
public int fExecuteNonQuery(string query)
{
OracleCommand command = new OracleCommand(query, this.OracleConn);
return command.ExecuteNonQuery();
}
public OracleDataReader fExecuteReader(string query)
{
OracleCommand command = new OracleCommand(query, this.OracleConn);
return command.ExecuteReader();
}
public object fExecuteScalar(string query)
{
OracleCommand command = new OracleCommand(query, this.OracleConn);
return command.ExecuteScalar();
}
public int fSelectAndFillDataSet(string query, DataSet dataset)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset);
}
public int fSelectAndFillDataSet(string query, DataSet dataset, string srcTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset, srcTable);
}
public int fSelectAndFillDataSet(string query, DataSet dataset, int startRecord, int maxRecords, string srcTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset, startRecord, maxRecords, srcTable);
}
public int fSelectAndFillDataTable(string query, DataTable dataTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataTable);
}
public void fSelectAndFillWebDataGrid(string query, DataGrid dataGrid)
{
DataSet dataset = new DataSet();
this.fSelectAndFillDataSet(query, dataset);
dataGrid.DataSource = dataset;
dataGrid.DataBind();
}
public void fSelectAndFillWinFormDataGrid(string query, DataGrid dataGrid)
{
DataSet dataset = new DataSet();
this.fSelectAndFillDataSet(query, dataset, "Items");
dataGrid.SetDataBinding(dataset, "Items");
dataGrid.Refresh();
}
}
public class DriverMsAccess
{
private OleDbDataAdapter DataAdapter;
private string itsConnStr;
private OleDbConnection OleDbConn;
public DriverMsAccess(string ACCESS_FILE)
{
this.itsConnStr = new clsConnStr().fMakeConnStr_Access(ACCESS_FILE);
this.OleDbConn = new OleDbConnection();
this.DataAdapter = new OleDbDataAdapter();
this.DataAdapter.SelectCommand = new OleDbCommand("", this.OleDbConn);
this.OleDbConn.ConnectionString = this.itsConnStr;
this.OleDbConn.Open();
}
public void fClose()
{
this.OleDbConn.Close();
}
public int fExecuteNonQuery(string query)
{
OleDbCommand command = new OleDbCommand(query, this.OleDbConn);
return command.ExecuteNonQuery();
}
public OleDbDataReader fExecuteReader(string query)
{
OleDbCommand command = new OleDbCommand(query, this.OleDbConn);
return command.ExecuteReader();
}
public object fExecuteScalar(string query)
{
OleDbCommand command = new OleDbCommand(query, this.OleDbConn);
return command.ExecuteScalar();
}
public int fSelectAndFillDataSet(string query, DataSet dataset)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset);
}
public int fSelectAndFillDataSet(string query, DataSet dataset, string srcTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset, srcTable);
}
public int fSelectAndFillDataSet(string query, DataSet dataset, int startRecord, int maxRecords, string srcTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataset, startRecord, maxRecords, srcTable);
}
public int fSelectAndFillDataTable(string query, DataTable dataTable)
{
this.DataAdapter.SelectCommand.CommandText = query;
return this.DataAdapter.Fill(dataTable);
}
public void fSelectAndFillWebDataGrid(string query, DataGrid dataGrid)
{
DataSet dataset = new DataSet();
this.fSelectAndFillDataSet(query, dataset);
dataGrid.DataSource = dataset;
dataGrid.DataBind();
}
public void fSelectAndFillWinFormDataGrid(string query, DataGrid dataGrid)
{
DataSet dataset = new DataSet();
this.fSelectAndFillDataSet(query, dataset, "Items");
dataGrid.SetDataBinding(dataset, "Items");
dataGrid.Refresh();
}
}
public class clsConnStr
{
private string CONNECTION_STRING_ACCESS = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={ACCESS_FILE}";
private string CONNECTION_STRING_MYSQL = "server={SQL_SERVER};user id={SQL_USER}; password={SQL_PASSWORD}; database={SQL_DB}; pooling=false";
private string CONNECTION_STRING_ORACLE = "User ID={SQL_USER};Data Source={SQL_DB};Password={SQL_PASSWORD}";
private string CONNECTION_STRING_SQLSERVER = "packet size=4096;user id={SQL_USER};data source={SQL_SERVER},{SQL_PORT};persist security info=True;initial catalog={SQL_DB};password={SQL_PASSWORD}";
public string fMakeConnStr_Access(string ACCESS_FILE)
{
return this.CONNECTION_STRING_ACCESS.Replace("{ACCESS_FILE}", ACCESS_FILE);
}
public string fMakeConnStr_MySql(string MYSQL_SERVER, string MYSQL_USER, string MYSQL_PASSWORD, string MYSQL_DB, string MYSQL_PORT)
{
return this.CONNECTION_STRING_MYSQL.Replace("{SQL_SERVER}", MYSQL_SERVER).Replace("{SQL_USER}", MYSQL_USER).Replace("{SQL_PASSWORD}", MYSQL_PASSWORD).Replace("{SQL_DB}", MYSQL_DB).Replace("{SQL_PORT}", MYSQL_PORT);
}
public string fMakeConnStr_Oracle(string ORACLE_USER, string ORACLE_PASSWORD, string ORACLE_DB)
{
return this.CONNECTION_STRING_ORACLE.Replace("{SQL_USER}", ORACLE_USER).Replace("{SQL_PASSWORD}", ORACLE_PASSWORD).Replace("{SQL_DB}", ORACLE_DB);
}
public string fMakeConnStr_SqlServer(string SQLSERVER_SERVER, string SQLSERVER_USER, string SQLSERVER_PASSWORD, string SQLSERVER_DB)
{
return this.CONNECTION_STRING_SQLSERVER.Replace("{SQL_SERVER}", SQLSERVER_SERVER).Replace(",{SQL_PORT}", "").Replace("{SQL_USER}", SQLSERVER_USER).Replace("{SQL_PASSWORD}", SQLSERVER_PASSWORD).Replace("{SQL_DB}", SQLSERVER_DB);
}
public string fMakeConnStr_SqlServer(string SQLSERVER_SERVER, string SQLSERVER_PORT, string SQLSERVER_USER, string SQLSERVER_PASSWORD, string SQLSERVER_DB)
{
return this.CONNECTION_STRING_SQLSERVER.Replace("{SQL_SERVER}", SQLSERVER_SERVER).Replace("{SQL_PORT};", SQLSERVER_PORT + "Network=DBMSSOCN;").Replace("{SQL_USER}", SQLSERVER_USER).Replace("{SQL_PASSWORD}", SQLSERVER_PASSWORD).Replace("{SQL_DB}", SQLSERVER_DB);
}
}
}
|