Note that there are some explanatory texts on larger screens.

plurals
  1. POC# when trying to add a next button geting negative value error
    primarykey
    data
    text
    <p>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</p> <p>"Index was out of range.Must be non-negative and less than the size of the collection. Parameter name: index"</p> <p>Heres the code i am using for this </p> <pre><code>namespace WindowsFormsApplication1 { public partial class Form1 : Form { client c1; int counter = 0; string results = ""; List&lt;House&gt; loadedHouses = new List&lt;House&gt;(); 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 &lt; 0) return; if ((loadedHouses != null) &amp;&amp; (value &gt; 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 &lt; 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(); } } } </code></pre> <p>Any Ideas?</p> <p>Thank You</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload