繁体   English   中英

我需要检查以表格形式输入的数据是否存在于数据库中,以及是否存在将其重定向到另一个页面

[英]I need to check whether the data entered in form exists in database or not and if it exists redirect it to another page

我的简短查询是,我需要仅使用LINQ查询表达式检查登录表单数据,以检查用户在名称中输入的值是否与数据库中列名下的所有值进行比较,如果存在,我想选择该特定行名称字段与之匹配的用户,并将用户重定向到另一个“仪表板”页面。 如果在数据库中找到记录到变量查询中,下面的代码将存储并选择行,现在无法检查查询中的变量是否指向数据库表中的任何行(如果已选择)。

 <%@ 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; } } } 

您是否从C#代码中尝试了此操作?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM