2016-10-24 49 views
0

我的簡短查詢是我需要檢查登錄表單數據,用戶輸入的值是使用LINQ查詢表達式僅對數據庫中列名下的所有值進行檢查,如果存在,我想選擇名稱字段與之匹配的特定行,並將用戶重定向到另一個儀表板頁面。 下面是存儲和選擇行的代碼,如果在數據庫中找到記錄到變量query.Now它不能檢查查詢中的變量是否指向任何行(如果選擇或不選擇數據庫表)。我需要檢查表單中輸入的數據是否存在於數據庫中,是否存在將數據重定向到另一個頁面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SessionHandling.aspx.cs" Inherits="WebApplication5.SessionHandling" %> 
 

 
<!DOCTYPE html> 
 

 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head runat="server"> 
 
    <title></title> 
 
</head> 
 
<body> 
 
    <form id="form1" runat="server"> 
 
    <div> 
 
     <h1> 
 
      THIS IS LOGIN FORM 
 
     </h1> 
 
     Name:&nbsp;&nbsp;&nbsp; 
 
     <asp:TextBox ID="txtName" runat="server"></asp:TextBox> 
 
     <br /> 
 
     <br /> 
 
     E-mail:&nbsp;&nbsp; 
 
     <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> 
 
&nbsp; 
 
     <br /> 
 
     <br /> 
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> 
 
    
 
    </div> 
 
    </form> 
 
</body> 
 
</html>

using System; 
 
using System.Collections.Generic; 
 
using System.Linq; 
 
using System.Web; 
 
using System.Web.UI; 
 
using System.Web.UI.WebControls; 
 

 
namespace WebApplication5 
 
{ 
 
    public partial class SessionHandling : System.Web.UI.Page 
 
    { 
 
     DataClasses1DataContext db = new DataClasses1DataContext(); 
 
     protected void Page_Load(object sender, EventArgs e) 
 
     { 
 

 
     } 
 

 
     protected void Button1_Click(object sender, EventArgs e) 
 
     { 
 
      tblContact tb = new tblContact(); 
 
      var query = from x in db.tblContacts where x.name == txtName.Text select x; 
 
      
 
      
 
     } 
 
    } 
 
}

回答

0

你從你的C#代碼試試這個?

if (query.Any()) 
{  
Response.Redirect("http://www.microsoft.com") 
} 
else 
{ 
Response.Redirect("http://www.google.com") 
} 
+0

這是一個簡單的方法,不需要問我,但無論如何謝謝! –

+0

不客氣 – pix

相關問題