【发布时间】:2011-03-23 15:44:17
【问题描述】:
我是 LINQ 的新手。我有一个使用 LINQ 填充的 GridView。我的 LINQ 语句从上一页获取查询字符串。查询字符串为字符串格式。代码如下:
protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryString["EntityID"];
int getIntEntity = Int32.Parse(getEntity);
OISLinqtoSQLDataContext db = new OISLinqtoSQLDataContext();
var tr = from r in db.Users
join s in db.Entities on r.UserID equals s.ID
where s.ID = Request.QueryString["EntityID"]
select new
{
//To Show Items in GridView!
};
GridView1.DataSource = tr;
GridView1.DataBind();
}
s.ID 不等于 QueryString。 S.ID 是 int 类型,QS 是 string 类型。我应该如何将此 QS 转换为整数?谢谢!
【问题讨论】:
-
您已经将 QueryString 转换为 int -
getIntEntity。只需在查询中使用它即可。 -
是的,凯文做到了。但是在我的 JOIN 中有一个错误显示:错误连接子句中的表达式之一的类型不正确。调用“加入”时类型推断失败。
标签: c# asp.net linq-to-sql web-applications