C# 从SQL Server检索一行到Windows Phone

C# 从SQL Server检索一行到Windows Phone,c#,windows-phone-7,C#,Windows Phone 7,我正在使用此代码在SQL Server中搜索数据。但结果是返回到列表,我应该返回什么才能只得到一行呢?意味着我想使用textblock绑定来获取记录,而不使用listbox模板 public List<Customer> FindProfile(string custemail) { var findprofile = from r in cust.Customers where r.CustEmail == custemail select r; return fi

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

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;
        }
公共列表FindProfile(字符串custemail)
{
var findprofile=来自客户中的r,其中r.CustEmail==客户电子邮件选择r;
返回findprofile.ToList();
}
公共列表GetProfileData()
{
var profiledata=来自客户中的r
选择r;
返回profiledata.Take(5.ToList();
}
公共档案()
{
初始化组件();
proxy.FindProfileCompleted+=新事件处理程序(proxy\u FindProfileCompleted);
proxy.FindProfileAsync(custemail);
}
无效代理\u FindProfileCompleted(对象发送方,FindProfileCompletedEventArgs e)
{
ListBox1.ItemsSource=e.结果;
}

您不能在返回的客户列表中使用
.First()
.FirstOrDefault()

List<Customer> customers = GetProfileData();

// get just the first customer:
Customer first = customers.First();
List customers=GetProfileData();
//仅获得第一个客户:
Customer first=customers.first();

您不能在返回的客户列表中使用
.First()
.FirstOrDefault()

List<Customer> customers = GetProfileData();

// get just the first customer:
Customer first = customers.First();
List customers=GetProfileData();
//仅获得第一个客户:
Customer first=customers.first();

@marc_s Thnx。但是我不想使用列表框模板。它是textblock可以绑定而不使用列表框模板吗?@browneyeo:好吧,现在你有了一个
客户
-你应该可以将它绑定到一个textblock-不?我忘了添加无效代理。。那么我应该放什么来代替lisbox1.ItemSource=e.Result@Browneyeo:这是一个完全不同的问题——这个问题是关于从SQL Server获取一行数据的——已经回答了。请把你的另一个问题放到一个单独的WPF问题@marc_s Thnx中。但是我不想使用listbox模板。它是textblock可以绑定而没有listbox模板吗?@Browneyeo:好吧,现在你有了一个
客户
-你应该可以将它绑定到一个textblock上-不?我忘了添加无效代理。。那么我应该放什么来代替lisbox1.ItemSource=e.Result@Browneyeo:这是一个完全不同的问题——这个问题是关于从SQL Server获取一行数据的——已经回答了。请将您的其他问题放入单独的WPF问题中