Object reference not set to an instance of an object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varunapj
    New Member
    • Feb 2008
    • 5

    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.NullRefe renceException: Object reference not set to an instance of an object.

    Source Error:


    Line 25: Protected Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click
    Line 26:
    Line 27: con.ConnectionS tring = "Data Source=varun-150d9d396\sqlex press;Initial Catalog=user;In tegrated Security=True;P ooling=False"
    Line 28: con.Open()
    Line 29: pr = DropDownList1.S electedValue


    Source File: C:\Documents and Settings\V A R U N S\My Documents\Visua l Studio 2005\WebSites\h ome\newb.aspx.v b Line: 27

    Stack Trace:


    [NullReferenceEx ception: Object reference not set to an instance of an object.]
    newb.Button1_Cl ick(Object sender, EventArgs e) in C:\Documents and Settings\V A R U N S\My Documents\Visua l Studio 2005\WebSites\h ome\newb.aspx.v b:27
    System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +96
    System.Web.UI.W ebControls.Butt on.RaisePostBac kEven t(String eventArgument) +116
    System.Web.UI.W ebControls.Butt on.System.Web.U I.IPo stBackEventHand ler.RaisePostBa ckEvent(String eventArgument) +31
    System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEve ntHandler sourceControl, String eventArgument) +32
    System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCol lection postData) +72
    System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3838


    Can any one help me i can proceed becoz of this error
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Can you paste the code which defines the con object?

    line 27: con.ConnectionS tring == "yada yada yada...";

    the con object has not been initialised and hence is null. Due to which accessing its properties / methods will throw exceptions

    Comment

    • dip_developer
      Recognized Expert Contributor
      • Aug 2006
      • 648

      #3
      post your code to have an idea.....

      Comment

      • varunapj
        New Member
        • Feb 2008
        • 5

        #4
        Got t

        i got it actually i have to specify like this
        Dim con as new sqlconnection

        Comment

        Working...