Link to home
Start Free TrialLog in
Avatar of kvnsdr
kvnsdr

asked on

C# ASP.NET Winforms DataGrid DataSet Foreach?

The following code fills a listbox very well, however I would like to recieve the same result using a datagrid for both asp and winforms apps.

foreach(DataRow dataRow in dataSet1.Tables["resultData"].Rows)
{
    listBox1.Items.Add(dataRow["ArticleNumber"].ToString());  //Displays results from SQL statement
}
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Hi There,

You want to add rows to a datagrid or wat? pls. Clarify.

Regards,
Chinmay
You fill the DataGrid directlly

Create a DataTable and fill it withyour data, then Bind the dataTable to your DataGrid
Avatar of kvnsdr
kvnsdr

ASKER

Well I'm attempting to replace the "listbox1" in this code with a "DataSet".

foreach(DataRow dataRow in dataSet1.Tables["resultData"].Rows)
{
    listBox1.Items.Add(dataRow["ArticleNumber"].ToString());  //Displays results from SQL statement
}

Q. Is there anyway a DataReader could work to quickly load a DataGrid in place of a DataSet?
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial