日期:2014-05-17  浏览次数:20867 次

做课程设计的时候遇到了麻烦,希望各位老师给指点指点!
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("学生登录"))
                        {
                          &nbs