anything wrong with line 29?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karenkksh
    New Member
    • Jun 2007
    • 15

    anything wrong with line 29?

    Hi,

    Server Error in '/WebSite1' Application.
    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 27: MyConnection.Op en();
    Line 28:
    Line 29: MyCommand = new SqlCommand("sel ect * from users where user_id='" + Request.QuerySt ring["id"].ToString() + "'", MyConnection);
    Line 30: MyAdapter = new SqlDataAdapter( MyCommand);
    Line 31: MyDataSet = new DataSet();




    Source File: c:\Documents and Settings\karen\ My Documents\Visua l Studio 2005\WebSites\W ebSite1\Admin\U serEdit.aspx.cs Line: 29

    Stack Trace:

    [NullReferenceEx ception: Object reference not set to an instance of an object.]
    Admin_UserEdit. Page_Load(Objec t sender, EventArgs e) in c:\Documents and Settings\karen\ My Documents\Visua l Studio 2005\WebSites\W ebSite1\Admin\U serEdit.aspx.cs :29
    System.Web.Util .CalliHelper.Ev entArgFunctionC aller(IntPtr fp, Object o, Object t, EventArgs e) +13
    System.Web.Util .CalliEventHand lerDelegateProx y.Callback(Obje ct sender, EventArgs e) +45
    System.Web.UI.C ontrol.OnLoad(E ventArgs e) +80
    System.Web.UI.C ontrol.LoadRecu rsive() +49
    System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3745

    Plz help. Tq

    Karen
  • enggwaqas
    New Member
    • Jun 2007
    • 19

    #2
    Originally posted by karenkksh

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

    Source Error:

    Line 27: MyConnection.Op en();
    Line 28:
    Line 29: MyCommand = new SqlCommand("sel ect * from users where user_id='" + Request.QuerySt ring["id"].ToString() + "'", MyConnection);
    Line 30: MyAdapter = new SqlDataAdapter( MyCommand);
    Line 31: MyDataSet = new DataSet();



    Karen
    Make sure that id exists in your query string i.e.
    the url to this page should look some thing like this:
    http://..../yourpage.aspx?id=someValue

    Comment

    • saran23
      New Member
      • Mar 2008
      • 28

      #3
      Originally posted by karenkksh
      Hi,

      Server Error in '/WebSite1' Application.
      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 27: MyConnection.Op en();
      Line 28:
      Line 29: MyCommand = new SqlCommand("sel ect * from users where user_id='" + Request.QuerySt ring["id"].ToString() + "'", MyConnection);
      Line 30: MyAdapter = new SqlDataAdapter( MyCommand);
      Line 31: MyDataSet = new DataSet();




      Source File: c:\Documents and Settings\karen\ My Documents\Visua l Studio 2005\WebSites\W ebSite1\Admin\U serEdit.aspx.cs Line: 29

      Stack Trace:

      [NullReferenceEx ception: Object reference not set to an instance of an object.]
      Admin_UserEdit. Page_Load(Objec t sender, EventArgs e) in c:\Documents and Settings\karen\ My Documents\Visua l Studio 2005\WebSites\W ebSite1\Admin\U serEdit.aspx.cs :29
      System.Web.Util .CalliHelper.Ev entArgFunctionC aller(IntPtr fp, Object o, Object t, EventArgs e) +13
      System.Web.Util .CalliEventHand lerDelegateProx y.Callback(Obje ct sender, EventArgs e) +45
      System.Web.UI.C ontrol.OnLoad(E ventArgs e) +80
      System.Web.UI.C ontrol.LoadRecu rsive() +49
      System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3745

      Plz help. Tq

      Karen



      Hi, Null reference exception Will be raised when any object is null,
      So Check for everything in the line of code, The connection string must be initialised correctly, the table name must be correct,
      I think there is some problem with the quotation marks used to enclose the value, Check this, Set a breakpoint in the line and check for the values.

      Thanks
      Saravanan

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        I would bet money on it coming from:
        Request.QuerySt ring["id"].ToString()

        You should be verifying that Request.QuerySt ring["id"] actually exists before building a string with it.

        Comment

        Working...