Populate list from typed dataset

Bubbly
Posted by Bubbly under C# category on | Views : 2542
First of all you need to define the typed dataset. For example, Here Employee is name of my xsd.
private Employee tdsEmp;


//Call this on your button click event
PopulateListFromTDS();


A table in a typed dataset is used to populate a list box with employee name from the employee table. A typed dataset provides design time verification of table names and field names before the program is run.
 private void PopulateListFromTDS()
{
string s;
int i;
//Clear Items in listBox
lstResults.Items.Clear();
for(i=0;i<=tdsEmp.EmpTDS.Count - 1;i++) //EmpTDS is table
{
// Check to see if row is flagged deleted.
if (tdsEmp.EmpTDS[i].RowState != DataRowState.Deleted)
{
s = tdsEmp.EmpTDS[i].empName.ToString();
lstResults.Items.Add(s);
}
}
}

Comments or Responses

Login to post response