| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 308 人关注过本帖
标题:各位大哥,有个问题,Combobox问题,选了省份,对应的市没有变化
只看楼主 加入收藏
云鹤
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2011-6-24
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
各位大哥,有个问题,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"));
                        }
                    }
                }
            }
        }
    }
}
搜索更多相关主题的帖子: private public 大哥 
2011-09-06 10:00
girl0001
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:56
专家分:118
注 册:2010-7-17
收藏
得分:20 
index值并没有变化。要放在private void cmd省_SelectedIndexChanged(object sender, EventArgs e)
事件里。
2011-09-06 20:21
云鹤
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2011-6-24
收藏
得分:0 
回复 2楼 girl0001
也是一样没有变化的,但是,现在自己弄懂了,谢谢您!
2011-09-07 20:31
快速回复:各位大哥,有个问题,Combobox问题,选了省份,对应的市没有变化
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030001 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved