1

我正在使用此代码在 SQL Server 中搜索数据。但结果是返回列表,我应该返回什么才能只得到一行?意味着我想使用文本块绑定来获取记录而不使用列表框模板..

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

1 回答 1

1

你不能只使用.First().FirstOrDefault()在被退回的客户名单上吗?

List<Customer> customers = GetProfileData();

// get just the first customer:
Customer first = customers.First();
于 2012-06-19T14:23:35.707 回答