数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

MyGeneration:dOOdad提供的数据绑定


发布日期:2021年07月18日
 
MyGeneration:dOOdad提供的数据绑定

数据绑定

()绑定到DataGrid(WebApp)

if(empsLoadAll())

{

dvEmps=empsDefaultView;

dgEmpsDataSource=dvEmps;

dgEmpsDataBind();

}

()绑定到ComboBox(WinApp)

//getdata

empsQueryAddResultColumn(EmployeesColumnNamesEmployeeID);

empsQueryAddResultColumn(EmployeesColumnNamesLastName);

empsQueryAddOrderBy(EmployeesColumnNamesLastName

WhereParameterDirASC);

empsQueryLoad();

//bindtocombobox

cmbEmployeesDisplayMember=EmployeesColumnNamesLastName;

cmbEmployeesValueMember=EmployeesColumnNamesEmployeeID;

cmbEmployeesDatasource=empsDefaultView;

()绑定到DropDownList(WebApp)

//getdata

empsQueryAddResultColumn(EmployeesColumnNamesEmployeeID);

empsQueryAddResultColumn(EmployeesColumnNamesLastName);

empsQueryAddOrderBy(EmployeesColumnNamesLastName

WhereParameterDirASC);

empsQueryLoad();

//bindtodropdownlist

ddlEmployeesDatasource=empsDefaultView;

ddlEmployeesDataTextField=EmployeesColumnNamesLastName;

ddlEmployeesDataValueField=EmployeesColumnNamesEmployeeID;

ddlEmployeesDatabind();

特殊函数执行自定义存储过程和SQL语句

Examples:

)LoadFromSql:(从数据库中检索并返回检索结果集查询结果保存到DataTable中)

ListDictionaryParms=newListDictionary();

ParmsAdd(@parameterNamevalue);

ParmsAdd(@parameterNamevalue);

parmsAdd……

if(thisLoadFromSql(proc_GetSpecialEmployeeParms))

{

}

)LoadFromSqlNoExec:(执行无结果集的存储过程返回受影响的行数)

int NbrOfChecks = thisLoadFromSqlNoExec(proc_CalculatePayroll);

例如删除一条记录dOOdad提供的文档中的方法是先LoadByPrimaryKey再MarkAsDeleted最后再Save进数据库这个过程要对数据库进行两次操作实际上我们可以只操作一次数据库(直接用dOOdads模板生成的存储过程)而不用先Load

ListDictionary Parms = new ListDictionary();

ParmsAdd(@ID empID);

int effectLine = thisLoadFromSqlNoExec(proc_EmployeeDeleteParms);

)LoadFromSqlReader:(返回SqlDataReader)

SqlDataReader rdr = thisLoadFromSqlReader(proc_GetSpecialEmployee Parms) as SqlDataReader;

)LoadFromSqlScalar:(返回单个值)

DateTime EarliestHireDate;

ListDictionary Parms = new ListDictionary();

ParmsAdd(@Active );

EarliestHireDate = ConvertToDateTime(thisLoadFromSqlScalar(GetEarliestHireDateParms));

)LoadFromRawSql:

thisLoadFromRawSql(SELECT MIN(EM_HireDate) FROM tEmployees WHERE EM_Active = {});

事务处理:

TransactionMgrtx=TransactionMgrThreadTransactionMgr();

try

{

Employeesemps=newEmployees();

empsAddNew();

empsFirstName=Jimmy;

empsLastName=Doe;

Productsprds=newProducts();

prdsAddNew();

prdsProductName=LunchBox;

prdsDiscontinued=false;

txBeginTransaction();

empsSave();

prdsSave();

txCommitTransaction();

}

catch(Exceptionex)

{

txRollbackTransaction();

TransactionMgrThreadTransactionMgrReset();

}

上一篇:站点导航控件数据动态从数据库加载

下一篇:Server对象:数据格式化