开发者

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 adv开发者_StackOverflow社区ance.

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜