using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
namespace ADONET
{
/// <summary>
/// sanjiliandong.xaml 的交互逻辑
/// </summary>
public partial class sanjiliandong : Window
{
public sanjiliandong()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DataTable table = SqlHelper.ExecuteDataTable("select * from AreaFull where AreaPid = 0");
List<Area> listPro = new List<Area>();
foreach(DataRow row in table.Rows){
Area area = new Area();
area.AreaId = (int)row["AreaId"];
area.AreaName= (string)row["AreaName"];
listPro.Add(area);
}
lbPro.ItemsSource = listPro;
}
private void lbPro_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Area AreaPro =(Area)lbPro.SelectedItem;
DataTable table = SqlHelper.ExecuteDataTable("select * from AreaFull where AreaPid = @AreaPid", new SqlParameter("@AreaPid",AreaPro.AreaId));
List<Area> listCity = new List<Area>();
foreach (DataRow row in table.Rows)
{
Area area = new Area();
area.AreaId = (int)row["AreaId"];
area.AreaName = (string)row["AreaName"];
listCity.Add(area);
}
lbCity.ItemsSource = listCity;
}
private void lbCity_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Area AreaCity = (Area)lbCity.SelectedItem;
DataTable table = SqlHelper.ExecuteDataTable("select * from AreaFull where AreaPid = @AreaPid", new SqlParameter("@AreaPid", AreaCity.AreaId));
List<Area> listXian = new List<Area>();
foreach (DataRow row in table.Rows)
{
Area area = new Area();
area.AreaId = (int)row["AreaId"];
area.AreaName = (string)row["AreaName"];
listXian.Add(area);
}
lbXian.ItemsSource = listXian;
}
}
}
做出来效果以后 点击省再点县市以后再选省 会出错,这个是因为什么资源没有释放的原因 还是什么原因 ,怎么解决这个??、 |