首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

干课程设计的时候遇到了麻烦,希望各位老师给指点指点

2013-11-29 
做课程设计的时候遇到了麻烦,希望各位老师给指点指点!using Systemusing System.Collections.Genericusi

做课程设计的时候遇到了麻烦,希望各位老师给指点指点!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 成绩管理
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("学生登录");
            comboBox1.Items.Add("教师登录");
            comboBox1.SelectedIndex = 0;
            comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cstr = @"Data Source=.;Initial Catalog=login;Integrated Security=True";
            string sql = string.Format("select count(*) from login where Name='{0}'and Pwd='{1}'", textBox1.Text.Trim(), textBox2.Text.Trim());
            using (SqlConnection conn = new SqlConnection(cstr))
            {
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    conn.Open();
                    MessageBox.Show("连接成功!");
                    int n = Convert.ToInt32(cmd.ExecuteScalar());
                    if (n >= 1)
                    {
                        if (comboBox1.SelectedText.Equals("学生登录"))
                        {
                            student fa = new student();
                            fa.Show();
                        }
                        else
                        {
                            teacher th = new teacher();
                            th.Show();
                        }
                    }
                    else
                        MessageBox.Show("您输入的用户名或密码有误!");
                }
            }
        }
    }
}
这是我的代码,运行时不管我选择的是学生登录还是教师登录跳转出来的都是teacher的那个窗口!!! c#

数据库
[解决办法]
if (comboBox1.SelectedText.Equals("学生登录"))
=>
if (comboBox1.Text.Equals("学生登录"))
[解决办法]
写错了,纠正一下:

 private void Form1_Load(object sender, EventArgs e)
{
(!IsPostBack)
{
    comboBox1.Items.Add("学生登录");
    comboBox1.Items.Add("教师登录");
    comboBox1.SelectedIndex = 0;
    comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
}
}


还有选择学生或老师,可以改用RaditionButton,因为只有两个选择

热点排行