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 6737051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:12:09+00:00 2026-05-26T11:12:09+00:00

Creating a client server application i have managed to get the server to link

  • 0

Creating a client server application i have managed to get the server to link to the database and send all the records over to the client and it shows the first record in all the correct text boxes but when i try and click on my next button it shows the error

“Index was out of range.Must be non-negative and less than the size of the collection. Parameter name: index”

Heres the code i am using for this

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        client c1;
        int counter = 0;
        string results = "";
        List<House> loadedHouses = new List<House>();

        public Form1()
        {
            InitializeComponent();
            c1 = new client();
            c1.runClient();
            textBox1 = Convert.ToString(Counter);


        }

        private int _counter; //It defaults to 0, setting it to 0 is redundant.
        public int Counter
        {
            get { return _counter; }
            set
        {
            if (Equals(_counter, value)) return;

            if (value < 0) return;

            if ((loadedHouses != null) && (value > loadedHouses.Count)) return;

            _counter = value;

            GetHouse();
        }
        }



        private void GetFirst()
        {
            Counter = 0;
        }
        private void Getprevious()
        {
            Counter--;
        }
        private void Getnext()
        {
            Counter++;
            GetHouse();
        }
        private void Getlast()
        {
           Counter = ((loadedHouses == null) ? 0 : loadedHouses.Count);
        }



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Funsold_Click(object sender, EventArgs e)
        {

        }

        private void Fsold_Click(object sender, EventArgs e)
        {

        }

        private void Fall_Click(object sender, EventArgs e)
        {
            string aQuery = "SELECT * FROM houses";


            string result = c1.getStringfromServer(aQuery);

            string[] Rows = result.Split('*');

            //try
            //{

                foreach (string r in Rows)
                {



                    string[] h = new string[5];
                    h = r.Split(',');
                    MessageBox.Show(h[0]);
                    // need to show the first record
                    House newhouse = new House();
                    if (h[0] == "")
                    {
                        MessageBox.Show("ARRRHHHJJJ CRASH!");
                    }
                    else
                    {
                        newhouse.ID = int.Parse(h[0]);


                    newhouse.Address = Convert.ToString(h[1]);
                    newhouse.Type = Convert.ToChar(h[2]);
                    newhouse.Cost = int.Parse(h[3]);
                    newhouse.Sold = Convert.ToString(h[4]);

                    loadedHouses.Add(newhouse);

                    ID_Number.Text = Convert.ToString(h[0]);

                    address1.Text = Convert.ToString(h[1]);
                    type1.Text = Convert.ToString(h[2]);
                    cost1.Text = Convert.ToString(h[3]);
                    sold1.Text = Convert.ToString(h[4]);



                    }
                    }

        //    }

        //        catch (Exception qq)
        //{
        //    MessageBox.Show (qq.Message);
        //}

            }
        public void GetHouse()
        {
            int m = Counter;
            House thisHouse = Counter < loadedHouses.Count ? loadedHouses[Counter] : null;

            ID_Number.Text = Convert.ToString(thisHouse.ID);
            address1.Text = Convert.ToString(thisHouse.Address);
            type1.Text = Convert.ToString(thisHouse.Type);
            cost1.Text = Convert.ToString(thisHouse.Cost);
            sold1.Text = Convert.ToString(thisHouse.Sold);
        }

        private void Next_Click(object sender, EventArgs e)
        {
            Getnext();
        }

        }
    }

Any Ideas?

Thank You

  • 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-05-26T11:12:10+00:00Added an answer on May 26, 2026 at 11:12 am

    I don’t see anywhere in your code you guarding against going outside the bounds of the array.

    Here’s a suggestion to fix your issues…

        private int _counter; //It defaults to 0, setting it to 0 is redundant.
        public int Counter
        {
            get { return _counter; }
            set
            {
                if (Equals(_counter, value)) return;
    
                if (value < 0) return;
    
                if ((loadedHouses != null) && (value > loadedHouses.Count) return;
    
                _counter = value;
    
                GetHouse();
            }
        }
        ...
    
        private void GetFirst()
        {
            Counter = 0;
        }
        private void Getprevious()
        {
            Counter--;
        }
        private void Getnext()
        {
            Counter++;
        }
        private void Getlast()
        {
            //Counter = results.Count(); //WTF? Why results.Count() when results is a string??
            Counter = ((loadedHouses == null) ? 0 : loadedHouses.Count);
        }
    

    Though, you should also disabled/enable the buttons based on if the user should be able to click them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

gcc 4.4.1 C99 I am creating a client server application. I have a Makefile
I have to add e-mail notifications to a client server application. Notifications happen as
When creating a client server application (serversocket), would I create 2 seperate projects or
For learning purposes I am writing a socket based client/server application. I have designed
For learning purposes I am writing a socket based client/server application. I have designed
I want to create an application which will have a client and server components.
I'm creating an IM client/server application for the Android OS, and am currently putting
I am creating a file server application for school assignment. What I currently have
I'm creating a client-server application which communicates via a custom socket protocol. I'd like
I am creating a client server application using c sharp. The server is using

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.