Populate list from untyped DataSet

This code shows how to Populate list from untyped DataSet

A table in a dataset is used to populate a list box with employee name from the employee table. With the dataset the name of the table and field must be known at design time. If they are misspelled or mistyped an error will be generated only at runtime.

Define the dataset.

private DataSet dsEmp;

//Call this on your button click event


private void PopulateListFromDS()
string s;
int i;
//Clear items in ListBox
for(i=0; i <=dsEmp.Tables["EmplyeeDS"].Rows.Count - 1; i++)
// Check to see if row is flagged deleted.
if (dsEmp.Tables["EmplyeeDS"].Rows.RowState != DataRowState.Deleted)
// Get the product name for each record.
s = dsEmp.Tables["EmplyeeDS"].Rows["EmpName"].ToString();
// Add product name to the list box

Reference: http://angeldeeps.blogspot.com/2010/03/populate-list-from-untyped-dataset.html


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: