winform登录代码

Program.cs文件中

static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            //InitDataConfig();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FrmLogin frmLogin = new FrmLogin();
            if (frmLogin.ShowDialog() == DialogResult.OK)
            {
                frmLogin.Close();
                Application.Run(new FrmMain());
            }
        }

  login登录窗口代码:

private void btnLogin_Click(object sender, EventArgs e)
        {
            string UserName=txtUserName.Text.Trim();
            string UserPwd=txtUserPwd.Text.Trim();
            //用户名、密码不能为空
            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(UserPwd))
            {
                MessageBox.Show("用户名、密码不能为空!");
                return;
            }

            DbCore core = new DbCore(DatabaseType.SqlServer, connStr);
            core.Open();
            //对照品种数据绑定
            DataTable dt = core.ExecuteDataSet("select * from users where UserName='" + UserName + "' and UserPwd='" + UserPwd + "'").Tables[0];
       core.Close();

if (dt.Rows.Count > 0) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show("用户名或密码错误!"); return; } }
原文地址:https://www.cnblogs.com/zkwarrior/p/4929467.html