C# 如何制作一个登录表单,我的按钮什么都不做

C# 如何制作一个登录表单,我的按钮什么都不做,c#,winforms,C#,Winforms,首先,我是visual C新手。我试图用密码登录来创建一个简单的登录表单,但当我按下按钮时,什么也没发生。我想检查数据库中是否有在线用户 我不知道我在哪里犯了错误 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System

首先,我是visual C新手。我试图用密码登录来创建一个简单的登录表单,但当我按下按钮时,什么也没发生。我想检查数据库中是否有在线用户

我不知道我在哪里犯了错误

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SportStat.Forme
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private void btnUlaz_Click(object sender, EventArgs e)
        {
            ulaz();
        }
        private void ulaz()
        {
            if (txtPassword.Text == "")
            {
                MessageBox.Show("Morate upisati lozinku", "caption", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);             
                return;
            }
            var sql = "select * from users where password='" + txtPassword.Text + "'";
            var dt = sustav.puniDt(sql);
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("Neispravna lozinka", "caption", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                txtPassword.Focus();
                return;
            }
            if ((string)dt.Rows[0]["password"] != txtPassword.Text)
            {
                MessageBox.Show("Neispravna lozinka", "caption", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                txtPassword.Focus();
                return;
            }
            sustav i = new sustav();
            i.idUser = (int)dt.Rows[0]["idUser"];
            i.pswd = (int)dt.Rows[0]["pswd"];
            i.prezimeIme = (int)dt.Rows[0]["prezimeIme"];
            i.idKlub = (int)dt.Rows[0]["idKlub"];
            int count = i.pswd;
            if (count == 1)
            {
                MessageBox.Show("Login Successful!");
                this.Hide(); 

                frmMain fm = new frmMain();
                fm.Show();
            } 
            this.Close();
        }
        private void Form2_Load(object sender, EventArgs e)
        {

        }
    }
}

有人能帮我解决这个问题吗。

不能评论,太低了

尝试在表单上添加另一个按钮并调用ulaz;从那个新按钮

有时,若删除按钮并再次添加它们,或者复制粘贴代码,则方法会自动指定另一个名称

例如:

 private void btnUlaz_Click(object sender, EventArgs e)
    {
        ulaz();
    }

private void btnUlaz_Click_1(object sender, EventArgs e)
    {
        ulaz();
    }
第一个不行。
我不知道你的问题是否如此,但值得一试。

在哪里放弃?跟踪代码并跟踪它所做的事情,这应该会揭示为什么它没有做你期望的事情。如果不解释实际的错误,我们将很难帮助你。我们无法搜索您的代码。查找断点,它们将帮助您查看代码是否正在访问“ulaz”函数。如果是,那么您知道该函数内部存在问题。如果没有,那么代码链接到button.var sql=select*时可能会出现问题,其中password='+txtPassword.Text+';可能不是你的问题,但请不要这样做!使用SQL参数。另外:我想这远不是有效的代码,但只是用于协议:不要存储纯文本密码。当我尝试提交一个空文本框时,它不会做任何事情,它应该会显示一个错误msgTry来重新构建您的项目,然后再试一次。