Posts Tagged Dispose
Its been a while my apologies. I have been extremely busy.
This topic came up because in existing applications data binding at design time was heavily used. I personally avoid such data binding as much as possible because well in all honesty it causes me a lot of problems later on. I realize many of you live and die with it. So don’t take it personally.
So I am converting one of these apps to XAML and WPF. They insisted I maintain a ComboBox databind. As many of you know data binding has changed a bit in WPF from your standard application. I created a property to bind the ComboBox to. I set the DataContext of the page to itself, which I like to do. It lets me expose various properties and quickly bind to them. Have a great weekend!
public partial class Window1 : Window
DataContext = this;
private DataTable _dataTable = null;
private void LoadData()
SqlConnection cn = null;
SqlCommand cmd = null;
SqlDataAdapter adapter = null;
DataSet dataSet = null;
cn = new SqlConnection(“Data Source=MyMachine;Initial Catalog=MyDb;Integrated Security=True”);
cmd = new SqlCommand(“select top 1 * from MyTable”, cn);
adapter = new SqlDataAdapter(cmd);
dataSet = new DataSet();
_dataTable = dataSet.Tables;
if (cmd != null)
if (adapter != null)
if (dataSet != null)
if (cn != null)
public IEnumerable MyDataColumns