Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 22nd, 2004, 02:53 PM
Authorized User
 
Join Date: Jun 2004
Location: , , USA.
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object reference error

Hi folks: I just started to populate my dropdownlists dynamically and since then although the lists get populated, I get the following error when I click "AddToCart" process command:
Source Error:


Line 121: DropDownList ddlW = (DropDownList)e.Item.FindControl("ddlWidth");
Line 122:
Line 123: Server.Transfer("AddToCart.aspx?ProductID=" + e.CommandArgument.ToString()
Line 124: + "&shoecolor=" +
Line 125: ddlC.SelectedItem.Text +
Source File: c:\inetpub\wwwroot\perrys\shoedetails.aspx.cs Line: 123
_____________________
Here is my code file:
using System;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Perrys
{
    /// <summary>
    /// Summary description for shoeDetails.
    /// </summary>
    public class shoeDetails : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataList myData;
        protected System.Web.UI.WebControls.DropDownList ddlC;
        protected System.Web.UI.WebControls.DropDownList ddlS;
        protected System.Web.UI.WebControls.Label lblShoeName;
        protected System.Web.UI.WebControls.Label Label1;
        protected System.Web.UI.WebControls.DropDownList ddlColor;
        protected System.Web.UI.WebControls.RequiredFieldValidator ValidateColor;
        protected System.Web.UI.WebControls.Label Label2;
        protected System.Web.UI.WebControls.DropDownList ddlSize;
        protected System.Web.UI.WebControls.RequiredFieldValidator validateSize;
        protected System.Web.UI.WebControls.Label Label3;
        protected System.Web.UI.WebControls.DropDownList ddlWidth;
        protected System.Web.UI.WebControls.RequiredFieldValidator validateWidth;
        protected System.Web.UI.WebControls.ImageButton imgBtn;
        protected System.Web.UI.WebControls.DropDownList ddlW;


        public SqlDataReader fetchReader(string query, string db)
        {
            SqlConnection cnShoes = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

            SqlCommand cmdSelect = new SqlCommand(query, cnShoes);

            cnShoes.Open();

            return cmdSelect.ExecuteReader (CommandBehavior.CloseConnection);
        }

        public DataSet fetchData(string query, string db)
        {
            SqlConnection cnShoes = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

            SqlDataAdapter myAdapter = new SqlDataAdapter(query, cnShoes);

            DataSet myData = new DataSet();

            myAdapter.Fill(myData);

            return myData;
        }

        object fetchScalar(string query, string db)
        {
            SqlConnection cnShoes = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

            SqlCommand cmdSelect = new SqlCommand(query, cnShoes);

            cnShoes.Open();

            object scalar = cmdSelect.ExecuteReader();

            cnShoes.Close();

            return scalar;
        }


        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here


            string query = "select * from Shoes where ShoeID='" +
                Request.QueryString [ "id" ] + "'";

            SqlConnection cnShoes = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand cmdSelect = new SqlCommand(query, cnShoes);
            cnShoes.Open();
            SqlDataReader shoeReader = cmdSelect.ExecuteReader();
            if (shoeReader.Read() == true)
            {
                lblShoeName.Text = shoeReader["ShoeID"].ToString();
                if (lblShoeName.Text == "11")
                {

                    ddlColor.Items.Insert(0, "");
                    ddlColor.Items.Insert(1, "Black");
                    ddlSize.Items.Insert(0, "");
                    ddlSize.Items.Insert(1, "8");
                    ddlSize.Items.Insert(1, "8.5");

                }

            }
            cnShoes.Close();


            myData.DataSource = fetchReader ( query, "shoes");
            myData.DataBind();

        }

        private void processCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddToCart"))

            {

                DropDownList ddlC = (DropDownList)e.Item.FindControl("ddlColor");
                DropDownList ddlS = (DropDownList)e.Item.FindControl("ddlSize");
                DropDownList ddlW = (DropDownList)e.Item.FindControl("ddlWidth");

                Server.Transfer("AddToCart.aspx?ProductID=" + e.CommandArgument.ToString()
                    + "&shoecolor=" +
                    ddlC.SelectedItem.Text +
                    "&shoesize=" +
                    ddlS.SelectedItem.Text +
                    "&shoewidth=" + ddlW.SelectedItem.Text);
            }

        }
}
}
How do I go about rectifying this? Thanks.



Reply With Quote
  #2 (permalink)  
Old July 22nd, 2004, 02:56 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

I think you're better of posting this in a .NET related forum, as I think the problem is more related to .NET than it is to SQL Server.

You could also try to limit the amount of code you posted (if possible). Wading through tons of code you haven't written yourself is not much fun.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Where Is My Mind? by Pixies (Track 7 from the album: Surfer Rosa & Come On Pilgrim) What's This?
Reply With Quote
  #3 (permalink)  
Old July 22nd, 2004, 03:13 PM
Authorized User
 
Join Date: Jun 2004
Location: , , USA.
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sure. Thanks.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error - Object reference not set to an instance ? venkikrao VB.NET 2 July 5th, 2007 01:00 AM
Class Object reference error. mjhoagland ASP.NET 1.0 and 1.1 Basics 2 February 2nd, 2006 09:28 AM
Error in OleDBConnection : Object reference not se pvsunil Classic ASP Databases 0 April 9th, 2005 02:45 AM
Getting Error - "Object reference not set to an in peri C# 2 December 24th, 2004 11:20 AM
Object reference Error mrideout BOOK: Beginning ASP.NET 1.0 4 August 9th, 2004 07:29 AM



All times are GMT -4. The time now is 08:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.