基于SQL Server的登录错误 [英] Login error based on SQL server

查看:116
本文介绍了基于SQL Server的登录错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我输入用户名和密码,即使它在数据库中,也会显示无效的登录详细信息. sql代码正确吗?注册部分是正确的,但是登录时总会出现错误

everytime i key-in the username and password even if it is in the database it says invalid login details. IS the sql code correct? The registration part is correct but when it comes to login there will always be an error

private void button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=DESKTOP-CJGIQ74;Initial Catalog=Login;Integrated Security=True");
        con.Open();

        string newcome = "SELECT Name FROM register WHERE Name='" + textBox1.Text + "'and Password='" + textBox2.Text + "'";

        SqlDataAdapter adp = new SqlDataAdapter(newcome, con);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        DataTable dt = ds.Tables[0];

        if (dt.Rows.Count>=1)
        {
            settext = textBox1.Text;
            Admin_Main_Page AdminMainForm = new Admin_Main_Page();
            AdminMainForm.Show();
            this.Hide();
        }
        else
        {
            label4.Text = "Invalid Login Details";
        }

推荐答案

可以尝试一下!

SqlDataAdapter adp = new SqlDataAdapter();
DataSet ds = new DataSet();
adp.SelectCommand = new SqlCommand("Your SQL Statement Here", con);
adp.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count  > 0)
{
    settext = textBox1.Text;
    Admin_Main_Page AdminMainForm = new Admin_Main_Page();
    AdminMainForm.Show();
    this.Hide();
}
else{
   label4.Text = "Invalid Login Details";
}

这篇关于基于SQL Server的登录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆