我使用LINQ to SQL中的許多倍正常工作,但今天有些不對勁LINQ到SQL「選擇在哪裏」的問題(WPF C#4.0)
這是代碼,必須選擇從用戶表中的密碼。 我叫這個方法告訴賴特...結果不是密碼請看圖片。
public void GetPassword(int id)
{
using (HProDataContext db = new HProDataContext())
{
_CurrentPassword = (from p in db.users
where p.id == _CurrentID
select p.password).ToString();
}
}
這個我如何使用此方法
private void btnOK_Click(object sender, RoutedEventArgs e)
{
if (listView1.SelectedItems.Count < 1)
{
MessageBox.Show("Please Select User");
}
else if (listView1.SelectedItems.Count > 1)
{
MessageBox.Show("Please Select Only One User");
}
else
{
_CurrentID = Convert.ToInt32(listView1.SelectedValue);
GetPassword(_CurrentID);
if (PasswordBox.Password == _CurrentPassword)
{
MessageBox.Show("You r in");
}
else
{
//MessageBox.Show("Password Is incorrect, please try again");
MessageBox.Show(_CurrentPassword);
}
}
}
「選擇p.password」 可能返回多個結果 - 你不能簡單地做一個的ToString()(見丹尼爾的回答) –