我有以下代碼和數據庫,但我不理解問題。每當我嘗試運行程序時,它總是會引發此異常: System.Core.dll中發生了類型為'System.InvalidOperationException'的未處理異常在我的用戶數據庫中,有一行用戶名:majorcsanad和密碼:722308,當我嘗試使用名稱/密碼登錄時,它說它包含零元素。我的代碼如下:public partial class Login : Form{ szofttech2Entities context = new szofttech2Entities(); public Login() { InitializeComponent(); } private void buttonEnter_Click(object sender, EventArgs e) { var password = (from u in context.Users where u.UserName == textBoxUserName.Text select u.Password).Single(); if (textBoxPassword.Text == password) { Order order = new Order(); order.Show(); this.Hide(); } else { labelWrongUserPassword.Visible = true; } }}
為什么LINQ查詢不返回任何元素?
慕婉清6462132
2021-05-04 13:29:14