• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c#省市联动

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBHelper;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication1
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //string sql = "select * from  s_province";
            ////DataTableCollection dc = SqlHelper.GetTableText(sql, null);
            //MySqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.connectionString, CommandType.Text, sql, null);
            //while (dr.Read())
            //{
            //    zi a = new zi();
              
            //    comboBox1.DisplayMember = "ProvinceName";
            //    comboBox1.ValueMember = "ProvinceID";
            //    a.provinceID = Convert.ToInt32(dr[0]);
            //    a.provinceName = Convert.ToString(dr[1]);
            //    comboBox1.Items.Add(a);
            //}
            //comboBox1.SelectedIndex = 0;
            this.comboBox1.Items.Clear();
            string sql = "select * from s_province";
            DataSet ds = SqlHelper.ExecuteDataSetText(sql, null);
            comboBox1.DisplayMember = "ProvinceName";
            comboBox1.ValueMember = "ProvinceID";
            comboBox1.DataSource = ds.Tables[0];
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            //this.comboBox3.Items.Clear();
            //qu qx = (qu)comboBox2.SelectedItem;
            //int id = qx.cityID;
            //string sql = "select * from qu where quid=@id";
            //MySqlParameter p = new MySqlParameter("@id", id);
            //MySqlParameter[] pa = new MySqlParameter[] { p };
            //MySqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.connectionString, CommandType.Text, sql, pa);
            //while (dr.Read()) 
            //{
            //    comboBox3.Items.Add(dr[1]);
            //}
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           // this.comboBox2.Items.Clear();
            //zi ax = (zi)comboBox1.SelectedItem;

            //int id = ax.provinceID;
            
            //string sql = "select * from s_city where ProvinceID=@id";
            //MySqlParameter p = new MySqlParameter("@id", id);
            //MySqlParameter[] pa = new MySqlParameter[] { p };
            //MySqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.connectionString, CommandType.Text, sql, pa);
            //while (dr.Read())
            //{
            //    //qu q = new qu();
            //    //comboBox1.DisplayMember = "CityName";
            //    //comboBox1.ValueMember = "CityID";
            //    //q.cityID = Convert.ToInt32(dr[0]);
            //    //q.cityName = Convert.ToString(dr[1]);
            //    //comboBox2.Items.Add(q);
            //    comboBox2.Items.Add(dr[1]);
            //}
            string id = Convert.ToString(comboBox1.SelectedValue);
            load_city(id);

        
        }
        private void load_city(string provinceid) 
        {
            string sql = "select * from s_city where ProvinceID="+provinceid;
            DataSet ds = SqlHelper.ExecuteDataSetText(sql, null);
            comboBox2.DisplayMember = "CityName";
            comboBox2.ValueMember = "CityID";
            comboBox2.DataSource = ds.Tables[0];
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
    class zi
    {
        public string provinceName;
        public string ProvinceName
        {
            get { return provinceName; }
            set { provinceName = value; }
        }
        public int provinceID;
        public int ProvinceID
        {
            get { return provinceID; }
            set { provinceID = value; }
        }
    }

    class qu 
    {
        public string cityName;
        public string CityName
        {
            get { return cityName; }
            set { cityName = value; }
        }
        public int cityID;
        public int CityID
        {
            get { return cityID; }
            set { cityID = value; }
        }
    }
}

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#唯一id发布时间:2022-07-10
下一篇:
C#继承的特性发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap