DbNetData is a collection of cross vendor database interface classes for .NET written in C# providing a consistent and simplified way of accessing the following databases:
- SQL Server
- SQL Server CE (Compact Edition)
- Oracle
- Access
- Access 2007
- MySql
- DB2
- Visual FoxPro
- dBASE
- Paradox
- Pervasive
- Firebird
- VistaDB
- Postgresql
- Advantage
- Sybase
- Intersystems Cache
- SQLite
DbNetData uses the IDbConnection and IDbCommand interface classes to provide a single interface to a total of 18 different .NET Data Providers. In addition to the 4 Data Providers included with .NET (SqlClient, OracleClient, Odbc and OleDb) DbNetData also supports the following third party Data Providers.
- Sql Server CE (Compact Edition).
- Oracle (Oracles's Data Provider).
- Sybase
- MySql .Net Data Provider (Connector/Net)
- MyDirect (CoreLabs MySql Data Provider)
- Npgsql (PgFoundry's PostgreSql Data Provider)
- PostgreSqlDirect (Core Labs's PostgreSql Data Provider)
- Firebird
- Pervasive
- DB2
- VistaDB
- SybaseDataDirect (Sybase Data Provider from DataDirect)
- InterSystemsCache
- Advantage Advanage Data Provider.
- SQLite
Example Code
Selecting records from a table/view
using ( DbNetData Db = new DbNetData( ConfigurationManager.ConnectionStrings["nwind"]) )
{
Db.Open();
QueryCommandConfig Query = new QueryCommandConfig ("select * products");
Query.Params["discontinued"] = 1;
Db.ExecuteQuery(Query);
DiscontinuedProductsGridView.DataSource = Db.Reader;
DiscontinuedProductsGridView.DataBind();
}
Selecting a record from a stored procedure
using ( DbNetData Db = new DbNetData( ConfigurationManager.ConnectionStrings["nwind"]) )
{
Db.Open();
QueryCommandConfig Query = new QueryCommandConfig ("GetProductNameById");
Query.Params["ProductID"] = ProductID.Text;
Db.ExecuteSingletonQuery(Query); // Automatically reads first record
ProductName.Text = Db.ReaderValue("ProductName").ToString();
}
Updating a record in a table
using ( DbNetData Db = new DbNetData( ConfigurationManager.ConnectionStrings["nwind"]) )
{
Db.Open();
UpdateCommandConfig Update = new UpdateCommandConfig("products");
// It is only necessary to supply the table name as the full update statement is built automatically
Update.Params["productname"] = ProductName.Value;
Update.FilterParams["productid"] = ProductID.Value;
Db.ExecuteUpdate(Update );
}
Adding a new record to a table
using ( DbNetData Db = new DbNetData( ConfigurationManager.ConnectionStrings["nwind"]) )
{
Db.Open();
CommandConfig Insert = new CommandConfig("products");
// You only need to specify the table name. DbNetData will build the rest of
// the insert statement automatically using the parameters
Insert.Params["productname"] = ProductName.Value;
Insert.Params["categoryid"] = CategoryID.Value;
Insert.Params["description"] = ProductName.Description;
Insert.Params["discontinued"] = 0;
Db.ReturnAutoIncrementValue = true;
long ProductID = Db.ExecuteInsert(Insert);
}
Deleting a record from a table
using ( DbNetData Db = new DbNetData( ConfigurationManager.ConnectionStrings["nwind"]) )
{
Db.Open();
CommandConfig CmdConfig = new CommandConfig("products");
CmdConfig.Params["discontinued"] = 1;
Db.ExecuteDelete(CmdConfig);
}
Updating the database using a stored procedure
using ( DbNetData Db= new DbNetData( ConfigurationSettings.AppSettings[ "nwind" ] ) )
{
Db.Open();
CommandConfig CmdConfig = new CommandConfig("UpdateProductName");
CmdConfig.Params["productname"] = ProductName.Value;
CmdConfig.Params["productid"] = ProductID.Value;
Db.ExecuteNonQuery(CmdConfig);
}