错误-对象引用未设置为实例 [英] Error - Object Reference not set to an instance

查看:70
本文介绍了错误-对象引用未设置为实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

Line 673:        da.Fill(ds,"cv");
Line 674:        da=new OleDbDataAdapter(sql1,con);
Line 675:        da1.Fill(ds1,"cv");
Line 676:		int r=0,r1=0;
Line 677:		DataRow []rs;



我的代码在下面



My code is given below

void go(Object s, EventArgs e)
{
		string s1, s2;
        s1 = TextBox1.Text.Trim();
        s2 = TextBox2.Text.Trim();
      
        con.Open();
       	string sql = "select * from cv";
        string sql1 = "select * from cv";
        da=new OleDbDataAdapter(sql,con);
        da.Fill(ds,"cv");
        da=new OleDbDataAdapter(sql1,con);
        da1.Fill(ds1,"cv");
		int r=0,r1=0;
		DataRow []rs;
		DataRow []rs1;
		rs=ds.Tables["cv"].Select("email='"+s1+"'");
		r=rs.Length;
		           
            if (s1 == "" && s2 == "")
			{
                Label1.Text = "Please enter your Email ID and Password";
			}
            else 
			{
			if(r>0)
			{
			rs1=ds1.Tables["cv"].Select("pass='" +s2+"'");
			r1=rs1.Length; 
			if(r1>0)
			{
                Response.Redirect("account.aspx");
			}
			else
			{
                Label1.Text = "Email ID not registred or Check your Password";
			}
			}
			}
			
          con.Close();  
}

推荐答案

在实例化之前,您正在使用da1.前一行da=new OleDbDataAdapter(sql1,con);再次实例化da.看起来应该是da1=new OleDbDataAdapter(sql1,con);.

祝你好运.
You''re using da1 prior to instantiating it. The previous line da=new OleDbDataAdapter(sql1,con); instantiates da again. It looks like that should have been da1=new OleDbDataAdapter(sql1,con);.

Good luck.


1.乍一看说您的连接未正确打开
使用 Debugger 并将Try..Catch块放入 go()方法中,以检查连接是否正确打开.
1. first look says your connection is not open properly
Use Debugger and put Try..Catch block in go() method checkout if connection is properly open or not.


这篇关于错误-对象引用未设置为实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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