What’s a good way to get data from a datatable to its corresponding object? I’m guessing there’s a more efficient and cleaner method than how I’m currently doing it:
var username = dt_user.rows[0].columns[0];
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Check out the extensions in System.Data.DataSetExtensions. It provides a generic extension method Field with various overloads for DataRow.
The real power comes when accessing nullable primative types:
More information can be found here:
http://msdn.microsoft.com/en-us/library/system.data.datarowextensions.aspx