views:

128

answers:

1

Hi All,

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.

+1  A: 

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.

SirDemon
Thank you, But I want parameter based INSERT code with the use of Enterprise library Data Application block.Thanks in advance.
nunu
@nunu, If you know how to write SQL INSERTs, you use practically the same syntax. Both when it concerns the query itself, and the c# code to call it. The Database object created by the DataBaseFactory will work on OleDB, and instead of SqlCommand, you use OleDbCommand (if you even need to create one). If you don't know how to write a SQL INSERT, that's a completely different question.
SirDemon
Could you please look at my edited question and give me favour?Thanks.
nunu