Populate list from untyped dataset

Posted by Bubbly under C# category on | Views : 3096
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[i].RowState != DataRowState.Deleted)
// Get the product name for each record.
s = dsEmp.Tables["EmplyeeDS"].Rows[i]["EmpName"].ToString();
// Add product name to the list box

Comments or Responses

Login to post response