帮助纠正在datagrid的安全页面中加载数据的编码 [英] help in correcting the coding ofloading the data in seccure page in datagrid

查看:82
本文介绍了帮助纠正在datagrid的安全页面中加载数据的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在系统中具有登录名,在该系统中,我必须输入登录名和密码才能进入安全页面.安全页面的编码是无效的.但是数据网格无法从数据库中加载数据.什么是paroblem ????

SqlConnection conn =新的SqlConnection(数据源= PC \\ SQLEXPRESS;初始目录= mydb;集成安全性= True");
受保护的void Page_Load(对象发送者,EventArgs e)
{
如果(Session ["New"]!= null)
{
Label1.Text + = Session ["New"].ToString();

如果(!IsPostBack)
{

LoadGridView();

}
}
其他
{
Response.Redirect("Default.aspx");
}
}

私有void LoadGridView()
{
//conn.Open();
SqlDataAdapter da =新的SqlDataAdapter(从用户中选择*,其中username =""+ Session [" New] +"'',conn); //问题出在我想的那个查询中..
DataSet ds = new DataSet();
da.Fill(ds,"user");
GridView1.DataSource = ds.Tables [0];
GridView1.DataBind(); ;
//conn.Close();
}
//休假是为了注销
受保护的void Button1_Click(对象发送者,EventArgs e)
{
Session ["New"] = null;
Response.Redirect("Default.aspx");
} as

i have a login in system where i have to put the login and pasward to enter to the secure page. the coding for secure page is as fallow. but data gird is not loading data from the data base.. what is the paroblem????

SqlConnection conn = new SqlConnection("Data Source=PC\\SQLEXPRESS; Initial Catalog=mydb; Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (Session["New"] != null)
{
Label1.Text += Session["New"].ToString();

if (!IsPostBack)
{

LoadGridView();

}
}
else
{
Response.Redirect("Default.aspx");
}
}

private void LoadGridView()
{
//conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from user where username=''"+Session["New"]+"''", conn); // the problem is in that query i think..
DataSet ds = new DataSet();
da.Fill(ds, "user");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind(); ;
//conn.Close();
}
// the fallowing is for logout
protected void Button1_Click(object sender, EventArgs e)
{
Session["New"] = null;
Response.Redirect("Default.aspx");
}as

推荐答案

看,这不是您应该做的.您没有听取我的建议,而是继续逐字重新张贴了相同的问题.这使论坛充满了垃圾,现在其他版本将永远无法得到答案,除非您愿意做一些工作,否则这个版本也不会.正如我所说,您需要学习使用调试器.您需要确定正在运行的查询是什么,还需要确定返回的数据是什么.哦,您没有打开连接,为什么呢?您已添加标签,您检查的会话对象中是否有值?它运行还是爆炸?如果Session ["New"]为null,它将爆炸,因此我假设它不为null,在这种情况下,问题就变成了,您的数据集中是否有任何数据.您的gridview设计是否正确,还是将其设置为自动填充?

如果您想学习,则必须能够遵循一些说明,并且应该与花时间尝试帮助您的人一起工作,而不是寻找另一个随机的陌生人问同样的问题.如果您要对正确的答案进行投票/标记为正确的答案,也会有所帮助.
See, this is NOT what you''re supposed to do. Instead of taking my advice, you went ahead and reposted the same question, verbatim. This is flooding the forums with garbage, now that other version will never get answered, and unless you''re willing to do some work, nor will this one. As I said, you need to learn to use a debugger. You need to work out what the query is that you''re running, and you need to work out what data is coming back. Oh, you''re not opening your connection, why is that ? You''ve added a label, is there a value in the session object you check ? Does it run, or blow up ? It will blow up if Session["New"] is null, so I assume it''s not null, in which case, the question becomes, is there any data in your dataset. Is your gridview designed properly, or is it set to auto populate ?

If you want to learn, you have to be able to follow some instructions, and you should work with the person who has taken the time to try to help you, instead of looking for another random stranger to ask the same questions to. It would also help if you were to upvote/mark as correct the correct answers you are given.


这篇关于帮助纠正在datagrid的安全页面中加载数据的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆