返回首页

错误给在con.Open()---对象的一个​​实例对象参考NotSet会

我的CS代码如下

void sub(Object s, EventArgs e)

{con.Open();

com=con.CreateCommand();

com.CommandText="UPDATE cv SET name = '" + t1.Text.Trim() + "',pass='" + t3.Text.Trim() + "',pdob='" + t5.Text.Trim() + "',mob='" + t6.Text.Trim() + "',psex='" + d1.SelectedItem.Text.Trim() + "',pstatus='" + d2.SelectedItem.Text.Trim() + "',address='" + tax.Value + "',cobj='" + t7.Text.Trim() + "',eque='" + t8.Text.Trim() + "',etype='" + d1.SelectedItem.Text.Trim() + "',eyear='" + t9.Text.Trim() + "',edur='" + t10.Text.Trim() + "',sind='" + d1.SelectedItem.Text.Trim() + "',sjob='" + t11.Text.Trim() + "',scom='" + t12.Text.Trim() + "',sdate='" + t13.Text.Trim() + "',sdur='" + t14.Text.Trim() + "' where email='" + t2.Text.Trim() + "'";

try{

com.ExecuteNonQuery();

System.Web.UI.WebControls.Label lbl1=new System.Web.UI.WebControls.Label();

lbl1.ForeColor=System.Drawing.Color.Yellow;

lbl1.BackColor=System.Drawing.Color.Blue;

lbl1.Text="Your record UPDATED sucessfully";

ph1.Controls.Add(lbl1);

}

catch(Exception ex)

{

Response.Write(ex.Message);

}

con.Close();

}

回答

评论会员:游客 时间:2012/02/07
thatraja下:了解这个错误imgsrc=在您的代码,CON对象未初始化,所以在调试检查其价值。确保您已分配的值(ConnectionString中,等等),CON对象和使用参数化查询,以避免SQL注入攻击
OriginalGriff
评论会员:游客 时间:2012/02/07
可能你已经忘记了该方法的代码行,或可能在其他地方(负载的方法,构造,我们不能从数量有限的代码告诉你提供):{C},您将通过您的代码做一个搜索,和wrok,它应该是
!山姆Anthwal:你可能不创建的连接对象
使用方法:
例如:SqlConnection的CON =新的SqlConnection("QueryString中");
然后检查连接对象
例如:如果(con! = NULL)
{
做点事
}