2012-06-19 48 views
1

我正在使用此代碼在SQL Server中搜索數據。但結果是返回列表,我應該返回它只獲得一行?意味着我要使用文本塊結合來獲得,而無需使用列表框模板記錄..從SQL Server檢索一行到Windows Phone

public List<Customer> FindProfile(string custemail) 
{ 
    var findprofile = from r in cust.Customers where r.CustEmail == custemail select r; 
    return findprofile.ToList(); 
} 

public List<Customer> GetProfileData() 
{ 
    var profiledata = from r in cust.Customers 
         select r; 
    return profiledata.Take(5).ToList(); 
} 

public pgProfile() 
{ 
    InitializeComponent(); 
    proxy.FindProfileCompleted += new EventHandler<FindProfileCompletedEventArgs>(proxy_FindProfileCompleted); 
    proxy.FindProfileAsync(custemail); 
} 

void proxy_FindProfileCompleted(object sender, FindProfileCompletedEventArgs e) 
     { 
      ListBox1.ItemsSource = e.Result; 
     } 

回答

1

你就不能使用.First().FirstOrDefault()獲取返回客戶的名單上?

List<Customer> customers = GetProfileData(); 

// get just the first customer: 
Customer first = customers.First(); 
+0

@ marc_s Thnx.but但我不想使用列表框模板。是否它的文本塊可以綁定沒有列表框模板? –

+0

@Brownieyeo:好吧,現在你有一個'客戶' - 你應該能夠將它綁定到一個文本塊 - 沒有? –

+0

我忘了添加無效代理..然後我應該把什麼,而不是lisbox1.ItemSource = e.Result; –