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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?