各位大哥,有个问题,Combobox问题,选了省份,对应的市没有变化
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 省市选择
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cmd省_SelectedIndexChanged(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(@"data source=.\sqlexpress;Attachdbfilename=|datadirectory|ss.mdf;Integrated security=true;User Instance=true;"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
= "select * from city where proid=@proid;";
cmd.Parameters.Add(new SqlParameter("proid", index));
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
cmd市.Items.Add(reader.GetString(reader.GetOrdinal("cityname")));
}
}
}
}
}
public int index = 0;
private void Form1_Load(object sender, EventArgs e)
{
cmd市.Items.Clear();
using (SqlConnection conn = new SqlConnection(@"data source=.\sqlexpress;Attachdbfilename=|datadirectory|ss.mdf;Integrated security=true;User Instance=true;"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
= "select * from promary";
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
cmd省.Items.Add(reader.GetString(reader.GetOrdinal("ProName")));
index=reader.GetInt32(reader.GetOrdinal("proid"));
}
}
}
}
}
}
}