请大家帮我看下我这个问题
public static void bind(GridView GD ,string st){
OleDbConnection con = connect.con();
OleDbDataAdapter da = new OleDbDataAdapter(st, con);
DataSet ds = new DataSet();
da.Fill(ds,"tab");
GD.DataSource = ds;
GD.DataMember = "tab";
GD.DataBind();
}//这一块是数据绑定的!
public static OleDbDataReader log(user p,string a)
{
OleDbConnection con = connect.con();
con.Open();
OleDbCommand com = new OleDbCommand(a, con);
OleDbDataReader dr = com.ExecuteReader();
return dr;
con.Close();
}//这个是查找数据库是否存在用户的!
protected void Button1_Click(object sender, EventArgs e)
{
user perp = new user();
perp.name = Tbname.Text;
perp.question = DDLqtion.Text;
perp.answer = TBanswer.Text;
string st = "select * from peoper where name='" + perp.name + "'and question='" + perp.question + "'and answer='" + perp.answer + "'";
if(operate.log(perp,st).Read())
{
string GVsrt = "select * from peoper where namer='" + perp.name + "'";
Panel2.Visible = true;
operate.bind(GView1, GVsrt);
}
else
{
Response.Write("<script>alert('你所回答的问题不对!请重新输入!')</script>");
Panel1.Visible = false;
Tbname.Text = "";
Tbname.Focus();
}
}//这是按钮的代码!
我的用意把log() bind()写在同一个类中,以方便重用。
问题出在 if(operate.log(perp,st).Read())
{
string GVsrt = "select * from peoper where namer='" + perp.name + "'";
Panel2.Visible = true;
operate.bind(GView1, GVsrt);
}
能查找得出来,但是就是不能数据绑定。查找后就绑定不了。不查找的话,我直接调用bind()又能绑定。
大家告诉下我原因 吧!
先谢谢了!
(代码作用就是为用户找回密码,回答问题正确后就把他原本的密码显示出来)我的思路就是先查找,再显示!