本文介绍了如何使用查询作为子句的Linq在Web应用程序中执行Sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用linq-to-sql来执行我的数据操作操作。我想使用Linq在Web应用程序中执行sql查询。我这样做了: 使用(DBUserDataContext db = new DBUserDataContext()) { str = @ 选择不同的 ltrim(rtrim(UserID))作为userText, ltrim(rtrim(UserID))as userValue from Users order by userID asc; var result = db.ExecuteQuery< User>(strSQL); result.ToList(); } 这里使用了userText和userValue,因为这用于绑定组合框中的值,如下所示 DataTextField = userText DataValueField = userValue 这样做,我收到错误结果中不存在所需的列'UserID'。然而,当我省略userText时,错误不会出现。但是我在组合框中显示的要求如果它不起作用还没完成。 任何帮助? 提前致谢.. 解决方案 请检查用户表列名(UserID)与用户类中的属性名称相同 public class 用户{ public 数据类型UserID {获取; 设置;} } 希望这有助于 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: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"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.. 解决方案 Please check the user table Column name (UserID) is same as the property name in User Classpublic class User{public datatype UserID{get;set;}}Hope this helps 这篇关于如何使用查询作为子句的Linq在Web应用程序中执行Sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 19:08