Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Enterprise library for OLEDB Access database

I want to use Microsoft Enterprise library Data Application Block for MS Access database (OLEDB provider)

I want parameter based INSERT functionality with enterprise library (Just like we do for SQL provider with parameter based code like - database.params.Add("@EmpName", this.EmpName);

I want the same thing for MS Access database connection.

Could anybody please let me know How could I do this?

Thanks in advance.

Will this code work?

SirDemon, Thanks for explanation.. I know everything related to INSERT, Update and Delete for SQL. I want compatible it with MS ACCESS . Okay tell me, is below code will work ?

string query = "INSERT INTO DB (EmployeeID, Name) VALUES (@EmployeeID, @Name)

Database db = DatabaseFactory.CreateDatabase();

DbCommand sqlCommand = db.GetCommandFromText(query);

db.AddInParameter(sqlCommand, "@EmployeeID", this.EmployeeID);
db.AddInParameter(sqlCommand, "@Name", this.Name);

Will this example will work in MS Access database.

like image 525
nunu Avatar asked Aug 04 '26 05:08

nunu


1 Answers

You can use OleDbCommand to set your parameters and query, just as you would do with SqlCommand on SQL Provider.

OleDbCommand Overview

OleDbCommand Class Members

To use your example:

string query = "INSERT INTO DB (EmployeeID, Name) VALUES (@EmployeeID, @Name)"

Database db = DatabaseFactory.CreateDatabase();

DbCommand command = db.db.GetSqlStringCommand(query);
db.AddInParameter(command, "@EmployeeID", this.EmployeeID);
db.AddInParameter(command, "@Name", this.Name);
db.ExecuteNonQuery(command);

Should work.

like image 124
SirDemon Avatar answered Aug 05 '26 20:08

SirDemon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!