Isn't working... I don't understand?

I'm trying to put together a very simple page where you can click the up and down button to move the item up or down in the list and save the new list into the database. I've run the stored procedure... and it works so Its not a procedure problem. Here is the list in my database

Order_Id        Item         Position

1                  Sebring     1

2                  GrandPrix  2

3                  Accord      4

4                  Miati         3

 

When I go to click the button I get a object reference not set to an instance of an object... This error haunts me many times.

Heres the code to my project:

BLL

 

        /// <summary>
        /// Gets Items from the Item table.
        /// </summary>
        /// <returns>A list of items.</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public OrderItemDataSet.OrderItemDataTable GetItemDataByPosition()
        {
            return OrderItemAdapter.GetItemDataByPosition();
        }

        /// <summary>
        /// Gets the order id based on the position specified.
        /// </summary>
        /// <returns>The order id.</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public int SelectOrderIdByPos(int pos)
        {
            return SelectOrderIdByPos(pos);
        }

        /// <summary>
        /// Update Order list.
        /// </summary>
        /// <param name="newPos">Position to change to.</param>
        /// <param name="originalPos">Original position.</param>
        /// <param name="orderId">Original id.</param>
        /// <param name="otherOrderId">Position to change id.</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public void ReorderItemByIdAndPosition(int newPos, int originalPos, int orderId, int otherOrderId)
        {
            OrderItemAdapter.ReorderItemByIdAndPosition(newPos, originalPos, orderId, otherOrderId);
        }
  

 Codebehind

  

1    using ReorderListWebApplication.BLL;
2    using System;
3    using System.Collections;
4    using System.Configuration;
5    using System.Data;
6    using System.Linq;
7    using System.Web;
8    using System.Web.Security;
9    using System.Web.UI;
10   using System.Web.UI.HtmlControls;
11   using System.Web.UI.WebControls;
12   using System.Web.UI.WebControls.WebParts;
13   using System.Xml.Linq;
14   
15   namespace ReorderListWebApplication
16   {
17       public partial class _Default : System.Web.UI.Page
18       {
19           protected void Page_Load(object sender, EventArgs e)
20           {
21   
22           }
23   
24           protected void UpButton_OnClick(object sender, EventArgs e)
25           {
26               Label posLabel = (Label)ReorderItemDataList.FindControl("PosLabel");
27               Label idLabel = (Label)ReorderItemDataList.FindControl("IdLabel");
28   
29               using (ReorderListWebApplication.BLL.OrderItem item = new ReorderListWebApplication.BLL.OrderItem())
30               {
31                   int pos = 0;
32   
33                   pos = item.SelectOrderIdByPos(Convert.ToInt32(idLabel.Text) - 1);
34   
35                   // Grab other orderId!!
36                   item.ReorderItemByIdAndPosition((Convert.ToInt32(posLabel.Text) - 1), Convert.ToInt32(posLabel.Text), 3, pos);
37               }
38           }
39   
40           protected void DownButton_OnClick(object sender, EventArgs e)
41           {
42               using (ReorderListWebApplication.BLL.OrderItem item = new ReorderListWebApplication.BLL.OrderItem())
43               {
44   
45               }
46           }
47       }
48   }
49   
 
~Marty
0
zeroAJAX
2/23/2008 8:27:11 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

8 Replies
1103 Views

Similar Articles

[PageSpeed] 29

When I go to click the button I get a object reference not set to an instance of an object... This error haunts me many times.

At what line in your code does this exception occur?


Rob Mills

www.dotnetadvisor.com
0
DotNetAdvisor
2/24/2008 1:16:06 AM

It breaks on this line: pos = item.SelectOrderIdByPos(Convert.ToInt32(idLabel.Text) - 1);
If I comment that out and set pos to a valid number... It'll break on the next line. ???


~Marty
0
zeroAJAX
2/25/2008 2:41:42 PM

Is the line "SelectOrderIdByPos" returning a null reference or throwing an exception?

 


Rob Mills

www.dotnetadvisor.com
0
DotNetAdvisor
2/25/2008 3:21:40 PM

The error message is "Object reference not set to an instance of an object." 


~Marty
0
zeroAJAX
2/25/2008 11:41:20 PM

Ok post the code for the "SelectOrderIdByPos" method.


Rob Mills

www.dotnetadvisor.com
0
DotNetAdvisor
2/26/2008 12:19:48 AM
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public int SelectOrderIdByPos(int pos)
        {
            return SelectOrderIdByPos(pos);
        }
 

~Marty
0
zeroAJAX
2/26/2008 12:43:07 AM

If I understand this correctly than your method is calling itself.  If so that will throw your code into an endless loop. 


Rob Mills

www.dotnetadvisor.com
0
DotNetAdvisor
2/26/2008 2:18:53 AM

HAHA... I laughed so hard when I read that. I can't believe I wrote that. Thanks! 


~Marty
0
zeroAJAX
2/26/2008 4:00:47 AM
Reply:

Web resources about - Isn't working... I don't understand? - asp.net.sql-datasource

Resonate Social For Facebook Helps Advertisers Understand Users’ Motivations
Why do Facebook users make the decisions they make? Resonate wants to help advertisers find out, so the digital marketing outfit launched Resonate ...

Facebook PMD Gigya releases Consumer Insights to better understand user identities
... allows marketers to easily query Gigya’s Identity Storage database and tie identity information with key performance indicators to understand ...

Genius — Search and understand the meaning of song lyrics, poetry, literature, and news on the App Store ...
Get Genius — Search and understand the meaning of song lyrics, poetry, literature, and news on the App Store. See screenshots and ratings, and ...

All sizes - Most people do not listen with the intent to understand; they listen with the intent to reply ...
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

"Understands" - YouTube
If Mitt Romney wins, the middle class loses. (Priorities USA Action is responsible for the content of this advertising)

Scientists continue search to understand Mers
The Mers coronavirus continues to confound scientists. To better understand the disease and determine where it comes from, a new project set ...

Explainer Video of the Day: Author John Green Helps You Understand Boko Haram
... in the news, but the situation in Nigeria with the Islamist terrorist group Boko Haram often gets overlooked and can be difficult to understand. ...



Businesses don't understand FTAs, so how will they deal with the TPP?
The government is keen to negotiate free trade agreements to bolster economic activity, but new research shows it has its work cut out to educate ...

Resources last updated: 12/9/2015 8:46:02 AM