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
}
LVL 1
kvnsdrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
Hi There,

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

Regards,
Chinmay
Mohammed NasmanSoftware DeveloperCommented:
You fill the DataGrid directlly

Create a DataTable and fill it withyour data, then Bind the dataTable to your DataGrid
kvnsdrAuthor Commented:
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?
Chinmay PatelChief Technology NinjaCommented:
Hi There,

Try this:
foreach(DataRow dataRow in dataSet1.Tables["resultData"].Rows)
{
    urDataSetName.Tables[0].Rows.Add(dataRow["ArticleNumber"].ToString());  //Displays results from SQL statement
}

Well, in WinForms you can directly bind a DataReader like we bind DataSet to the DataGrid,
in WebForms You'll have to manually add datat ot dataset and than finally bind it to DataGrid.

Regards,
Chinmay

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.