[英]Getting one row from a Strongly Typed dataset without getting who table
我目前有以下代碼:
/// <summary>
/// This is an ineffecient method of getting a tenant by their id.
/// </summary>
/// <param name="id">int ID of the tenant to be selected</param>
/// <returns>Tenant with the specific ID, or null if not found.</returns>
public static Tenant GetTenantByID(int id){
RentalEaseDataSetTableAdapters.tblTenantTableAdapter adapter = new RentalEaseLogic.Database.RentalEaseDataSetTableAdapters.tblTenantTableAdapter();
RentalEaseDataSet ds = new RentalEaseDataSet();
adapter.Fill(ds.tblTenant);
DataRow[] rows = ds.tblTenant.Select("ID = " + id);
if (rows.Length > 0) {
return new Tenant(rows[0] as RentalEaseDataSet.tblTenantRow);
} else {
return null;
}
}
這在性能上非常糟糕。 每當有人想要一行時,它都會抓取並加載一張大桌子。 一定有更好的方法。
如何從表中選擇一行,而不必填寫整個表並仍然保持強數據鍵入?
有。 將查詢與TableAdapter
關聯。 TableAdapter概述 ,主要是如何:創建TableAdapter查詢 。
然后,用查詢的行填充數據集。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.