數據綁定
()綁定到DataGrid(WebApp)
if(emps
LoadAll())
{
dvEmps = emps
DefaultView;
dgEmps
DataSource = dvEmps;
dgEmps
DataBind();
}
()綁定到ComboBox(WinApp)
//get data
emps
Query
AddResultColumn(Employees
ColumnNames
EmployeeID);
emps
Query
AddResultColumn(Employees
ColumnNames
LastName);
emps
Query
AddOrderBy(Employees
ColumnNames
LastName
WhereParameter
Dir
ASC);
emps
Query
Load();
//bind to combobox
cmbEmployees
DisplayMember = Employees
ColumnNames
LastName;
cmbEmployees
ValueMember = Employees
ColumnNames
EmployeeID;
cmbEmployees
Datasource = emps
DefaultView;
()綁定到DropDownList(WebApp)
//get data
emps
Query
AddResultColumn(Employees
ColumnNames
EmployeeID);
emps
Query
AddResultColumn(Employees
ColumnNames
LastName);
emps
Query
AddOrderBy(Employees
ColumnNames
LastName
WhereParameter
Dir
ASC);
emps
Query
Load();
//bind to drop
down list
ddlEmployees
Datasource = emps
DefaultView;
ddlEmployees
DataTextField = Employees
ColumnNames
LastName;
ddlEmployees
DataValueField = Employees
ColumnNames
EmployeeID;
ddlEmployees
Databind();
特殊函數執行自定義存儲過程和SQL語句
Examples:
()LoadFromSql:(從數據庫中檢索並返回檢索結果集查詢結果保存到DataTable中)
ListDictionary Parms = new ListDictionary();
Parms
Add(
@parameterName
value
);
Parms
Add(
@parameterName
value
);
parms
Add……
if(this
LoadFromSql(
proc_GetSpecialEmployee
Parms))
{
}
()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 = {});
事務處理:
TransactionMgr tx = TransactionMgr
ThreadTransactionMgr();
try
{
Employees emps = new Employees();
emps
AddNew();
emps
FirstName =
Jimmy
;
emps
LastName =
Doe
;
Products prds = new Products();
prds
AddNew();
prds
ProductName =
Lunch Box
;
prds
Discontinued = false;
tx
BeginTransaction();
emps
Save();
prds
Save();
tx
CommitTransaction();
}
catch(Exception ex)
{
tx
RollbackTransaction();
TransactionMgr
ThreadTransactionMgrReset();
}
From:http://tw.wingwit.com/Article/program/net/201311/13033.html