Hey_XXP 2017-12-06 12:45 采纳率: 0%
浏览 1592

C#用ShowDialog()跳转界面不能加载出东西 是我加了判断语句的问题嘛 执行不出来第一张那样的效果

图片说明图片说明图片说明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;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        comboBox1.SelectedIndex = 0;
    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
          //创建数据库连接字符串            SqlConnection connection = new SqlConnection(connString);  //通过connection对象创建数据库连接
        con.ConnectionString = "server=DESKTOP-3U564EO;database=library;uid=xxpxxplove;pwd=feinibuaiv5";
        string sql = string.Format("select count(*) from {2} where num='{0}'and password='{1}'", textBox1.Text,textBox2.Text , comboBox1.Text);  //创建sql语句
        con.Open();   //打开数据库连接
         //创建command对象
        SqlCommand command = new SqlCommand(sql,con);
        int num = (int)command.ExecuteScalar();   //执行sql查询语句,ExecuteScalar()返回查询结果集中的第一行的第一列
        if (num > 0)
        {
            MessageBox.Show("欢迎进入成绩管理系统!", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);  //弹出登录成功消息框
            this.Hide();  //当前窗口(登录窗口)不显示
            if (comboBox1.Text=="Administrator")
            {

                Form AMain = new Form();
                AMain.ShowDialog();
                this.Close();
                this.Dispose();


            }
            else
            {
                Form RMain = new Form();
                RMain.ShowDialog();
                this.Close();
                this.Dispose();
            }
        }
        else
        {
            MessageBox.Show("您输入的用户名或密码错误!", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
        con.Close();//关闭数据库连接
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
    }



}

}

  • 写回答

9条回答 默认 最新

  • X-Winter 2017-12-06 15:12
    关注

    你把你的程序运行的现象截几张图出来看看,把你的问题现象描述详细些。

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置