Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7890231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:18:07+00:00 2026-06-03T06:18:07+00:00

Can anybody help me with the issue I’m seeing? For some reason when I

  • 0

Can anybody help me with the issue I’m seeing? For some reason when I run my page, I get my drop down lists to populate the data, however the first item in my database, per each SQL query, doesn’t get populated.

For example, my database table is:

Category

1  Books
2  Clothing
3  Toys
4  Household Items

my first query –

SELECT Category FROM ProductCategories

my drop down list gets populated with

Clothing
Toys
Household Items

I have 2 other drop down lists I’m populating and those are doing the same thing. Once I get this figured out, I’ll try to figure out the other problem I’m having with inserting the data in the database.

Thank you!

public partial class InsertItems : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection connection;
        SqlCommand populateList;
        SqlDataReader reader;

        string connectionString = ConfigurationManager.ConnectionStrings["LakerBids"].ConnectionString;
        connection = new SqlConnection(connectionString);

        populateList = new SqlCommand("USE LakerBids SELECT Category FROM ProductCategories;" +
                                "USE LakerBids SELECT SubCategory FROM ProductSubCategories;" +
                              "USE LakerBids SELECT LName FROM Users", connection);
        if (!IsPostBack)
        {
            try
            {
                connection.Open();
                reader = populateList.ExecuteReader();

                while (reader.Read())
                {
                    pcategory.DataSource = reader;
                    pcategory.DataValueField = "Category";
                    pcategory.DataBind();
                }

                reader.NextResult();

                while (reader.Read())
                {
                    psubcategory.DataSource = reader;
                    psubcategory.DataValueField = "SubCategory";
                    psubcategory.DataBind();
                }

                reader.NextResult();

                while (reader.Read())
                {
                    user.DataSource = reader;
                    user.DataValueField = "LName";
                    user.DataBind();
                }

                reader.Close();
            }
            finally
            {
                connection.Close();
            }
        }
    }

    protected void AddItem(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            SqlConnection connection;
            SqlCommand insertData;

            string connectionString = ConfigurationManager.ConnectionStrings["LakerBids"].ConnectionString;
            connection = new SqlConnection(connectionString);
            insertData = new SqlCommand("INSERT INTO Products (ProductName, ProductDesc, CategoryID, SubCatID, StatusID, UserID, ReservePrice, AuctionLength, BidID)" +
            "VALUES (@ProductName, @ProductDesc, @CategoryID, @SubCatID, 1, @UserID, @ReservePrice, @AuctionLength, NULL)", connection);

            insertData.Parameters.Add("@ProductName", System.Data.SqlDbType.NVarChar, 50);
            insertData.Parameters["@ProductName"].Value = pname.Text;

            insertData.Parameters.Add("@ProductDesc", System.Data.SqlDbType.NVarChar, 200);
            insertData.Parameters["@ProductDesc"].Value = pdesc.Text;

            insertData.Parameters.Add("@CategoryID", System.Data.SqlDbType.Int);
            insertData.Parameters["@CategoryID"].Value = pcategory.SelectedIndex;

            insertData.Parameters.Add("@SubCatID", System.Data.SqlDbType.Int);
            insertData.Parameters["@SubCatID"].Value = psubcategory.SelectedIndex;

            insertData.Parameters.Add("@UserID", System.Data.SqlDbType.Int);
            insertData.Parameters["@UserID"].Value = user.SelectedIndex + 2;

            insertData.Parameters.Add("@ReservePrice", System.Data.SqlDbType.Money);
            insertData.Parameters["@ReservePrice"].Value = Convert.ToDecimal(reserveprice.Text);

            insertData.Parameters.Add("@AuctionLength", System.Data.SqlDbType.Int);
            insertData.Parameters["@AuctionLength"].Value = Convert.ToInt32(auctionlength.Text);

            try
            {
                connection.Open();
                insertData.ExecuteNonQuery();
                Response.Redirect("Categories.aspx");
            }
            catch (Exception error)
            {
                dberror.Text = error.ToString();
            }
            finally
            {
                connection.Close();
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:18:08+00:00Added an answer on June 3, 2026 at 6:18 am

    You need to either use a DataSet or populate business entities within a collection and then bind to the collection.

    List<Category> cats = new List<Category>();
    
    while (reader.Read()) 
    { 
       Category cat = new Category();
    
       // fill properties from DataReader
       cats.Add(cat);
    } 
    
    pcategory.DataSource = cats; 
    pcategory.DataValueField = "Category"; 
    pcategory.DataBind(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me with retrieving some elements from the following example text: sdfaasdflj
Can anybody help me how to run a python script through command line? My
Can anybody help me on following issue: I have code like: if(cond1 && cond2
Can anybody help me in finding out how to verify that _tmkdir succeeded. For
Can anybody help how to setup a automatic backup of mysql database and then
can anybody help me how to nice integrate doctrine 2.0 into ZF 1.10? I
Can anybody help me writing a regular expression to replace these characters with a
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
can anybody help me solve this : i got $filename= index 198.php; i use
Can anybody help with converting an SDL_Surface object, a texture loaded from a file,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.