Click here to Skip to main content
15,891,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var userDetails = db.Database.SqlQuery<Login>("exec [spGetUserDetails] @EmailID = {0}", login.EmailID).Select(x => new Login { LoginPassword = x.LoginPassword.ToString(), LoginPasswordSalt = x.LoginPasswordSalt }).ToList()[0];
Posted
Updated 11-Jan-16 1:18am
v2

1 solution

Try this:


C#
DataTable dt = new DataTable();

var userDetails = db.Database.SqlQuery<Login>("exec [spGetUserDetails] @EmailID = {0}", login.EmailID).Select(x => new Login { LoginPassword = x.LoginPassword.ToString(), LoginPasswordSalt = x.LoginPasswordSalt }).ToList()[0];

dt = (DataTable)userDetails;
 
Share this answer
 
Comments
Abrar Kazi 12-Jan-16 1:00am    
Thanks for the help but it didnt work. I tried this myself before posting my question, it says :
"Cannot convert type 'WPFL.ViewModel.Login' to 'System.Data.DataTable'"
deepankarbhatnagar 12-Jan-16 1:19am    
OK ,try to solve from these helpful links,

http://www.codeproject.com/Tips/70802/Convert-Linq-Query-Result-To-DataTable

http://www.codeproject.com/Questions/465327/Convert-LinQ-var-into-a-DataTable
Abrar Kazi 12-Jan-16 1:21am    
Ok sure. Thanks.
Abrar Kazi 13-Jan-16 3:01am    
It worked.

DataTable userinfoDataTable = new DataTable();
DataRow dr;

List<login> tuserDetails = db.Database.SqlQuery<login>("exec [spGetUserDetails] @EmailID = {0}", login.EmailID)
.Select(x => new Login { LoginPassword = x.LoginPassword.ToString(), LoginPasswordSalt = x.LoginPasswordSalt, UserID = x.UserID, EmailID = x.EmailID }).ToList();

userinfoDataTable.Columns.Add("UserID", typeof(int));
userinfoDataTable.Columns.Add("EmailID", typeof(string));

foreach (var i in tuserDetails)
{
dr = userinfoDataTable.NewRow();
dr["UserID"] = i.UserID;
dr["EmailID"] = i.EmailID;
userinfoDataTable.Rows.Add(dr);
}

DataTable finaldt = new DataTable();
finaldt = userinfoDataTable.Copy();


To all the coders: if u find a better way than this then do post and help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900