KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
UPDATE2 I started playing more with James suggestion of using reflection and got something working that will return a property value based on a string variable. I don't want to put this as an answer just yet though as I feel it is probably not the best solution. Here is the code: DataContext dataBase = new DataContext(); List<string> listOfFields = new List<string>; List<string> listOfUsers = new List<string> //strFields and strNames are strings generated from listOfFields and listOfUsers IEnumerable<myUserData> userInfo = dataBase.ExecuteQuery<myUserData> ("select " + strFields + " from myUserData where user_id in (" + strNames + ")"); foreach(var user in userInfo) { foreach(string field in listOfFields) { string fieldValue = user.GetType().GetProperty(field).GetValue(user,null).ToString Console.WriteLine(fieldValue); } } UPDATE: I am making progress! I think. This could be a very terrible solution and resource hog, I'm not sure yet, but it's better than the blank screens I've been getting. The issue now is finding a way to just return the values and not the field name with it. Here is my code: foreach(string userID in listOfUserIDs) { //dataBase is a Datacontext var userInfo = dataBase.myTable .Where("user_id == @0", userID) .Select("New(" + strFields + ")"); foreach(var user in userInfo) { Console.WriteLine(user); } } This outputs {first_name = JOHN, last_name = DOE} etc whatever other fields. I'm hoping I can find a way to modify my Select clause to just select the values. I am a novice programmer and especially new to C# and anything that invovles databases.This is my first project working with queries and databases and I'm running into problems with suc
Tags (comma-separated)
Save Edits
Cancel