基本信息
源码名称:SQLCE完整实例源码下载 (含数据文件,无需安装SQL server)
源码大小:0.98M
文件格式:.zip
开发语言:C#
更新时间:2014-07-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
城市联动
城市联动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlServerCe; namespace SelCity { public partial class Form1 : Form { private static string ConnectionString = "Data Source=\\FlashDisk\\basedata.sdf;password='zjs';"; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SqlCeConnection conn; SqlCeCommand cmd; string cmdstring = "select Province from Province "; conn = new SqlCeConnection(ConnectionString); cmd = new SqlCeCommand(cmdstring, conn); SqlCeDataAdapter da; da = new SqlCeDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "Province"); DataTable Dt; Dt = ds.Tables[0]; //comboBox1.DataBindings.Add("Text", Dt, "Province"); comboBox1.Text = Dt.Rows[0]["Province"].ToString(); for (int i = 0; i < Dt.Rows.Count - 1; i ) { comboBox1.Items.Add(Dt.Rows[i]["Province"].ToString()); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.Text != "") { comboBox2.Items.Clear(); //comboBox2.DataBindings.Clear(); SqlCeConnection conn; SqlCeCommand cmd; string cmdstring = "select City from City where Province='" comboBox1.Text "' group by Province,City"; conn = new SqlCeConnection(ConnectionString); cmd = new SqlCeCommand(cmdstring, conn); SqlCeDataAdapter da; da = new SqlCeDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "City"); DataTable Dt; Dt = ds.Tables[0]; //MessageBox.Show(Dt.Rows.Count.ToString()); //comboBox2.DataBindings.Add("SelectedItem", Dt, "city"); if (Dt.Rows.Count > 0) { comboBox2.Text = Dt.Rows[0]["city"].ToString(); } for (int i = 0; i < Dt.Rows.Count - 1; i ) { comboBox2.Items.Add(Dt.Rows[i]["city"].ToString()); } } else { } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox2.Text != "") { comboBox3.Items.Clear(); //comboBox3.DataBindings.Clear(); SqlCeConnection conn; SqlCeCommand cmd; string cmdstring = "select County from CityAreaCode where Province='" comboBox1.Text "' and city='" comboBox2.Text "' and County <> '' group by Province,city,County "; conn = new SqlCeConnection(ConnectionString); cmd = new SqlCeCommand(cmdstring, conn); SqlCeDataAdapter da; da = new SqlCeDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "CityAreaCode"); DataTable Dt; Dt = ds.Tables[0]; if (Dt.Rows.Count > 0) { comboBox3.Text = Dt.Rows[0]["County"].ToString(); } for (int i = 0; i < Dt.Rows.Count - 1; i ) { comboBox3.Items.Add(Dt.Rows[i]["County"].ToString()); } } else { } } } }