gpt4 book ai didi

c# - 如何从查询中获取值并将其与字符串进行比较?

转载 作者:行者123 更新时间:2023-11-29 12:30:13 25 4
gpt4 key购买 nike

这是我的 Society 表的架构:

Society(SocietyName, Email, Password, Status)

所以基本上我正在创建一个登录页面,用户在其中输入电子邮件和密码。如果有一封电子邮件与数据库中的电子邮件匹配,则会检查状态是否等于校长或教员或学生事务办公室。基于此,它重定向到不同的页面。以下是我的代码:

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

namespace WebApplication3 {
public partial class WebForm1 : System.Web.UI.Page {
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
MySql.Data.MySqlClient.MySqlDataReader reader;
String QueryStr;
String name;

protected void Page_Load(object sender, EventArgs e) { }
protected void clicked(object sender, EventArgs e) {
String ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["Webappconstring"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(ConnString);
conn.Open();
String QueryStr2 = "";
QueryStr = "";
QueryStr = "Select * from the_society_circle.society WHERE Email= '" + Emailtxt.Text + "' And Psswd=' " + passwordtxt.Text + "'";
cmd = new MySql.Data.MySqlClient.MySqlCommand(QueryStr, conn);
reader = cmd.ExecuteReader();

QueryStr2 = "Select Status from the_society_circle.society where Email = '" + QueryStr + "'";
name = "";
while (reader.HasRows && reader.Read()) {
name = reader["Email"].ToString();
}


if ((QueryStr2== "president" || QueryStr2 == "faculty member") && reader.HasRows ) {
Session["Email"] = name;
Response.BufferOutput = true;
Response.Redirect("WebForm2.aspx", true);
} else {
Emailtxt.Text = "invalid user";
}
conn.Close();
}
}
}

问题是 if 语句永远不会执行,并且它总是打印无效的用户。

PS:我是网络开发新手:D

最佳答案

您将 QueryString2 设置为此值

QueryStr2 = "Select Status from the_society_circle.society where Email = '" + QueryStr + "'";

它永远不可能是您检查的值之一。

关于c# - 如何从查询中获取值并将其与字符串进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27677923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com