27,581
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static string strConn = "Data Source=127.0.0.1;Initial Catalog=TestPARTITION;Persist Security Info=True;User ID=sa;PASSWORD=密码";
private void cbo院系_Enter(object sender, EventArgs e)
{
cbo院系.Items.Clear();
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string strSQL = "SELECT SchoolTable.Xname FROM SchoolTable";
SqlCommand cmd = new SqlCommand(strSQL, conn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
cbo院系.Items.Add(sdr[0]);
}
conn.Close();
}
private void cbo专业_Enter(object sender, EventArgs e)
{
cbo专业.Items.Clear();
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string strSQL = "SELECT MajorTable.Xname FROM MajorTable";
if (cbo院系.Text != "")
{
strSQL = "SELECT MajorTable.Xname FROM MajorTable WHERE MajorTable.Xno in (SELECT SchoolTable.Xno FROM SchoolTable WHERE SchoolTable.Xname='" + cbo院系.Text + "')";
}
SqlCommand cmd = new SqlCommand(strSQL, conn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
cbo专业.Items.Add(sdr[0]);
}
conn.Close();
}
private void cbo班级_Enter(object sender, EventArgs e)
{
cbo班级.Items.Clear();
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string strSQL = "SELECT ClassTable.Bno FROM ClassTable";
if (cbo专业.Text != "")
{
strSQL = "SELECT ClassTable.Bno FROM ClassTable WHERE ClassTable.Mno in (SELECT MajorTable.Mno FROM MajorTable WHERE MajorTable.Xname='" + cbo专业.Text + "')";
}
SqlCommand cmd = new SqlCommand(strSQL, conn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
cbo班级.Items.Add(sdr[0]);
}
conn.Close();
}
}
}