使用sql数据源从数据库获取数据并将其放入网格视图中所需的帮助 [英] Help needed in getting the data from database using sql datasource and putting it in the Grid View
本文介绍了使用sql数据源从数据库获取数据并将其放入网格视图中所需的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个场景,我已经创建了一个更新用户的网页,我想在其中使用sql数据源将特定用户的数据放在网格视图中。特定用户的ID来自会话,但是存在一个问题
I have a scenario where i have made a web page of update user, in which i want to put data of a specific user in grid view using sql data source. The id of specific user comes from session, but there is a problem that
AppUserID = Convert.ToInt32(Session["AppUserID"]);
但是在数据库中表用户id是int类型,
现在sql表达式变为
But in the database table the user id is of int type,
Now the sql expression becomes
[UserId] = @UserID and its Value is Session("AppUserID")
现在,它给出了错配数据类型的错误。
Now here, it gives the error of mismatch datatype.
推荐答案
你可以写一个这样的方法,应该可以工作。但是如果没有查询,你的测试就很难判断
you could write a method like this and should work. But without the query your are testing its hard to tell
public int AppUserID
{
get
{
object AppUserID= Session["AppUserID"] as object;
if (AppUserID == null)
{
int AppUserID= -1;
return AppUserID;
}
else
return AppUserID== null ? null : AppUserID as int;
}
set
{
Session["AppUserID"] = value;
}
}
这篇关于使用sql数据源从数据库获取数据并将其放入网格视图中所需的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文