I have a dataset containing a table as a data source for a list box in the
windows application depending on which radio button the user selects. The
table is disposed when the user clicks on other radio button.
I'm getting an error message that a column that I added previously alreday
exists in the dataset. Each table that I add to the dataset according to
which radio button is selected is disposed when it's de-selected. Why does
the system still thinks that the column is still there? Below is the code
for this section. Thanks for any help in advance, Alpha
private void radioPayPlan_CheckedChanged(object sender, System.EventArgs e)
{
try
{
if (radioPayPlan.Checked == true)
{
//Setup the PaySource in listbox
cmdLocal.CommandText = "select sID, scode, sname from tblsource" ;
saLocal.Fill(dsLocal,"source");
drv = (DataRowView) BindingContext[dsLocal.Tables["source"]].Current;
dsLocal.Tables["source"].AcceptChanges();
//Create new column
DataColumn sc = new
DataColumn("ScodeName",Type.GetType("System.String "));
sc.Expression = "iif(len(scode) > 0,scode + ': ' + sname,sname)";
dsLocal.Tables["source"].Columns.Add(sc);
//this.lstSelections.SelectedIndex = 1;
dvSource = new
DataView(dsLocal.Tables["source"],"","sname",DataViewRowState.CurrentRows);
this.lstSelections.DataSource = dvSource;
lstSelections.DisplayMember = "ScodeName";
lstSelections.ValueMember = "sID";
}
else
{
dsLocal.Tables["source"].Clear();
dsLocal.Tables["source"].Dispose();
dvSource.Dispose();
}
}
catch(Exception my_e)
{
MessageBox.Show("The system encountered an error loading listing
data:\n" + my_e.ToString());
}
}