Link to home
Start Free TrialLog in
Avatar of Barry Dunlap
Barry Dunlap

asked on

Dataset to c# class

I have a C# class in Visual Studio 2017 to hold values for columns of a SQL Server 2014 table.  I have a DataSet returned from a stored proc.  Can please you send a code sample that puts the values for each table column from the DataSet into the class that has corresponding names.  If you want the code for the class I can send it.
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Please see this link:
https://exceptionnotfound.net/mapping-datatables-and-datarows-to-objects-in-csharp-and-net-using-reflection/

Essentially you can build a mapping class and use reflection to bind columns to properties.
SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America 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
Avatar of Barry Dunlap
Barry Dunlap

ASKER

Thanks, Kyle.  I will copy this code to my project and see have it work.  I will have to adjust it to my column names, etc. but it appears to be what I need.  Thanks for responding quickly as I need to have this working now.
Barry Dunlap
Kyle, thanks for the link you sent.  That is very helpful and complete with code samples.
Barry.
ASKER CERTIFIED SOLUTION
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
Vadim,
I read what you wrote.  Very helpful.  Also, thanks for the links to Docs.  I am working through issues with a database table and a 7-table join stored proc.  It has caused trouble with how a two DataGridView controls are filled.  I did use adapter.fill(datatable) as you recommended, but the DataGridView did not fill.  I'll keep working on it as I probably missed something.  If I can't fix it, I probably should send a file with code so you can see my error.

Barry
SOLUTION
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