为什么会出现此错误对象引用未设置为对象的实例。在星标线上 [英] why this error comes Object reference not set to an instance of an object. on star mark line
问题描述
protected void btnsubmit_Click(object sender,EventArgs e)
{
* ob.fetch(从admin_reg中选择pwd,其中userid ='+ Session [uid ] .ToString());
if(ob.ds.Tables [0] .Rows.Count> 0)
{
if(txtcurpwd.Text.Trim()== ob.ds.Tables [0] .Rows [0] .ItemArray [0] .ToString())
{
if(ob.dml_statment(update admin_reg set pwd ='+ txtnewpwd.Text.Trim()+'where userid ='+ Session [uid]。ToString()+')> 0)
{
lblmsg.Text =密码已成功更改;
}
}
else
{
lblmsg.Text =密码无效;
}
}
else
{
lblmsg.Text =无效的用户名;
}
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
* ob.fetch("select pwd from admin_reg where userid='" + Session["uid"].ToString() );
if (ob.ds.Tables[0].Rows.Count > 0)
{
if (txtcurpwd.Text.Trim() == ob.ds.Tables[0].Rows[0].ItemArray[0].ToString())
{
if (ob.dml_statment("update admin_reg set pwd='" + txtnewpwd.Text.Trim() + "' where userid='" + Session["uid"].ToString() + "'") > 0)
{
lblmsg.Text = "Password Changed Successfully";
}
}
else
{
lblmsg.Text = "Invalid Password";
}
}
else
{
lblmsg.Text = "Invalid Userid";
}
}
推荐答案
无法完全按照您的方式运行代码,我们无法确切地说出来。
但是......我首先看一下Session
对象:如果那里没有对象uid,那么Session [uid ]将返回null
,您将在尝试在不存在的对象上使用ToString时出现该错误。
使用调试器,并查看值。然后找出它为什么是空的 - 这取决于你的其他代码!
Without being able to run your code, exactly as you did, we can't tell exactly.
But...I'd start by looking at theSession
object: if there is no object "uid" in there, then Session["uid"] will returnnull
and you will get that error trying to use ToString on a nonexistent object.
Use the debugger, and look at the values. Then work out why it's empty - which is down to your other code!
这篇关于为什么会出现此错误对象引用未设置为对象的实例。在星标线上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!