These are examples of using the Enterprise Library Data Access Application block.
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
public MyDataset.MyEntityDataTable GetAllEntities()
{
SqlDatabase db = new SqlDatabase(this.ConnectionString);
StringBuilder sql = new StringBuilder();
sql.Append("dbo.my_entity_select_all");
using (DbCommand command = db.GetStoredProcCommand(sql.ToString()))
{
using (MyDataset.MyEntityDataTable dt = new MyDataset.MyEntityDataTable())
{
using (IDataReader reader = db.ExecuteReader(command))
{
while (reader.Read())
{
AddMyEntityRow(dt, reader);
}
return dt;
}
}
}
}
public MyDataset.MyEntityDataTable GetMyEntity(string MyEntityId)
{
SqlDatabase db = new SqlDatabase(this.ConnectionString);
StringBuilder sql = new StringBuilder();
sql.Append("dbo.My_Entity_Select_By_My_Entity_ID);
using (DbCommand command = db.GetStoredProcCommand(sql.ToString()))
{
db.AddInParameter(command, "@EntityId", DbType.String, Entity_Alias);
using (MyDataset.MyEntityDataTable dt = new MyDataset.MyEntityDataTable())
{
using (IDataReader reader = db.ExecuteReader(command))
{
while(reader.Read())
{
AddMyEntityRow(dt, reader);
}
return dt;
}
}
}
}
No comments:
Post a Comment