Visual Studio 2012 Express 中的 C# 登录问题
本文关键字:登录 问题 中的 Express Studio 2012 Visual | 更新日期: 2023-09-27 17:55:18
伙计们,我正在一个项目中醒来,遇到了一些问题。它是一个写入本地数据库的基本登录应用程序。我知道在安全性方面这是不对的,但它仅用于概念验证。它在我的浏览器中验证并加载。然后,当我填写数据时,出现以下错误:
代码行突出显示:int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
错误如下:
SqlException 未由用户代码处理
"员工"附近的语法不正确
任何帮助不胜感激谢谢
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class LoginPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ShowUsersConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) form Staff where UserName='" + txtUserName.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); //
conn.Close();
if (temp == 1)
{
conn.Open();
string CheckPassQuery = "select password from Staff where UserName='" + txtUserName.Text + "'";
SqlCommand passcom = new SqlCommand(CheckPassQuery, conn);
string password = passcom.ExecuteScalar().ToString();
if (password == txtPassword.Text)
{
Session["New"] = txtUserName.Text;
Response.Write("Password correct");
Response.Redirect("Users.aspx");
}
else
{
Response.Write("Password is incorrect");
}
}
else
{
Response.Write("Username ivalid");
}
}
}
}
这是你的错误:
string checkuser = "select count(*) form Staff where UserName='" + txtUserName.Text + "'";
form
应该from
另外,研究SQL注入