2010-07-21 71 views
0

我現在有這樣的代碼:獲取一行從一個強類型數據集沒有得到誰的表

/// <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; 
     } 
    } 

這是性能非常可怕的。每次有人想要一行時,它會抓取並加載一張大表。一定有更好的方法。

如何從表格中選擇一行,而不必填充整個表格並仍然保持強大的數據類型?

回答

相關問題