Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top