我的简短查询是,我需要检查登录表单数据,由用户输入的值要对数据库中使用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:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
<br />
E-mail:
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<br />
<br />
<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")
}