日期:2014-05-19  浏览次数:20436 次

有错误...希望 高手来排错.....................................................
未将对象引用设置到对象的实例。  
说明:   执行当前   Web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。  

异常详细信息:   System.NullReferenceException:   未将对象引用设置到对象的实例。

源错误:  


行   82:                   myconn.ConnectionString   =   "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source= "   +   Server.MapPath( "../db/123.mdb ");
行   83:                   myconn.Open();     //打开数据库连接
行   84:               string   adminsql   =   "select   *   from   admin   where   name= ' "   +   text1.Text.Replace( " ' ",   " ' ' ")   +   " 'and   pwd= ' "   +   text2.Text.Replace( " ' ",   " ' ' ")   +   " ' ";
行   85:                   OleDbCommand   comm   =   new   OleDbCommand(adminsql,   myconn);   //存储过程
行   86:                   OleDbDataReader   reader   =   comm.ExecuteReader();
 

源文件:   c:\***\login.aspx.cs         行:   84  


怎么会..未将对象引用设置到对象的实例的呢??谢谢

------解决方案--------------------
Server.MapPath( "~/db/123.mdb ");
------解决方案--------------------
打印出来看看 string adminsql = "select * from admin where name= ' " + text1.Text.Replace( " ' ", " ' ' ") + " 'and pwd= ' " + text2.Text.Replace( " ' ", " ' ' ") + " ' ";
是不是写错了
------解决方案--------------------
string adminsql = "select * from admin where name= ' " + text1.Text.Replace( " ' ", " ' ' ") + " 'and pwd= ' " + text2.Text.Replace( " ' ", " ' ' ") + " ' ";
------------
这行代码里用到了text1,text2两个控件,确认他们实例化了.
------解决方案--------------------
前面加两行:
string s1=text1.Text.Replace( " ' ", " ' ' ");
string s2=text2.Text.Replace( " ' ", " ' ' ");
看看哪行有错?