Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using linq-to-sql in order to perform my data manipulation operation. I wanted to execute sql query in web application using Linq. I have done this:

C#
using (DBUserDataContext db = new DBUserDataContext())
{
   str = @"
        select distinct 
            ltrim(rtrim(UserID)) as userText,
            ltrim(rtrim(UserID)) as userValue 
        from Users order by userID asc";
       
    var result = db.ExecuteQuery<User>(strSQL);
    result.ToList();
}

Here as userText and as userValue are used because this is used to bind value in combobox as shown below"
C#
DataTextField = "userText"
DataValueField = "userValue"


In doing so, i am getting error " The required column 'UserID' does not exist in the results." However, when i omit as userText, the error is not coming. But my requirement to show in combo box will not work if it is not done.
Any help?
Thanks in advance..
Posted
Updated 27-Oct-14 19:01pm
v2
Comments
Laiju k 28-Oct-14 0:08am    
Check the column name is correct
DamithSL 28-Oct-14 0:29am    
can you update the question with User class code?

1 solution

Please check the user table Column name (UserID) is same as the property name in User Class
C#
public class User{
public datatype UserID{get;set;}
}

Hope this helps
 
Share this answer
 

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