object reference error

Posted by Dn2010 under ASP.NET on 2/6/2011 | Points: 10 | Views : 1394 | Status : [Member] | Replies : 4
hi friends,
error in this part

+ Server.MapPath("..\\login.mdb") +

this is full line
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0 ;data source=" + Server.MapPath("..\\login.mdb") + ";");
System.Data.OleDb.OleDbDataAdapter dap = new System.Data.OleDb.OleDbDataAdapter("Select * from Categories", con);

Error 1 An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.Server.get' D:\sample\Admin\AdminLogin.aspx.cs

Error 2 A field initializer cannot reference the nonstatic field, method, or property 'Admin_AdminPanel.con' D:\sample\Admin\AdminLogin.aspx.cs


please correct it.


thanks.




Responses

Posted by: Naimishforu on: 2/7/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
I'm not sure but object reference is required means your variable is not getting any values assign...try to debug the code and check for the runtime value of con variable!!

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 2/8/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Post your complete code...

Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: jayanthichebrolupanoramicworldbiz-8895 on: 2/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Server is property to System.Web.UI.Page class
so confirm whether you have use it in page body or not.

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 2/10/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Cross check if you have framed the connection string properly and the mdb file is in place.

Regards
Madhu

Thanks and Regards
Madhu

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response