stpatrck 15 Newbie Poster

What are you having trouble with? What code have you written? Where is it failing?

Generic questions like this have a horrible chance to be answered, especially if you don't provide some code to prove you've done some work.

If you post some code or make your question a little more specific in regards to where you are having trouble you're more likely to get assistance.

stpatrck 15 Newbie Poster

Is your break point ON the catch(exception ex) line or past it?

If your break point is ON the catch line the 'ex' variable has not been initiated or assigned yet. Try putting your break point IN your catch block.

If this is not the case could you supply some code? Object regerence not set to an instance of an object means you are trying to do work with data that is null. Without seeing your code it's very difficult to help.

stpatrck 15 Newbie Poster

I'm a teapot

Apparently the server is a teapot trying to make coffee and cannot serve pages to you.

stpatrck 15 Newbie Poster

Unity is an excellent game engine. It's free and supports cross-platform deployment including web, iOS, Android and more.

stpatrck 15 Newbie Poster

Try using TOP 'N' in your select statement...

SELECT TOP 3 * ... ORDER BY {scoreColumnName} DESC

This works with MSSQLServer. It may be different depending on the DB Server you are running.

stpatrck 15 Newbie Poster

is 'counterr' in your last statement supposed to be the int counter defined above it? If so...

rs = statement.executeQuery("SELECT * FROM Quiz WHERE SrNo = " + counter + ";");
stpatrck 15 Newbie Poster

If you are not restricted to using an array you may want to consider List<Student>. This would simplify your code to be something like...

Initialize the list of students

var ClassList = new List<Student>();

Modify your add click to...

private void btnAdd_Click(object sender, EventArgs e)
        {
            // Create new student and assign name etc provided by user
            Student _Student = new Student();
            _Student.Name = txtName.Text;
            _Student.Surname = txtSurname.Text;
            _Student.Age = Convert.ToInt32(txtAge.Text);
            _Student.ITMark = Convert.ToInt32(txtIT.Text);
            _Student.MathMark = Convert.ToInt32(txtEng.Text);
            _Student.EngMark = Convert.ToInt32(txtMath.Text);

            // ... omitted for brevity

            ClassList.Add(_Student);

            // .. clear input controls.
        }

Then no changes are needed to your display method

private void displayAll_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            for (int j = 0; j < ClassList.Count(); j++)
            {
                richTextBox1.Text += ("Student: " + Convert.ToString(j) +
                                     "\nName: " + ClassList[j].Name +
                                     "\nSurname: " + ClassList[j].Surname +
                                     "\nAge: " + ClassList[j].Age +
                                     "\nStudent Average: " + Convert.ToString(ClassList[j].AverageMark) +
                                     "\n" + "\n");
            }
            //MessageBox.Show("Display all students.");
        }
ddanbe commented: for overall effort :) +15
stpatrck 15 Newbie Poster

On a side note, I prefer to use the Length property over the Count() extension method when dealing with arrays.

A good thread about array.length vs array.count()

stpatrck 15 Newbie Poster

If you are initializing an array with the size of 50 ClassList.Count() will always be fifty no matter how many Students you add to the list. This means that your 'for' loop is looking at null positions. Here are a couple of suggestions to try.

First, since you already have a 'counter' for the number of students that have been added you can use it in place of the 'ClassList.Count()' in your 'for' loop on line 108.

...
for(int i = 0;i<CountStudents;i++){
    // do work with ClassList[i]...
}

Second, put a check in your 'for' loop to make sure the object in the ClassList[j] position is not null. Simply add a quick check for null.

...
if(ClassList[j] == null) 
    break;  // You can also use continue; if you do want to loop through the entire array.

// do work with ClassList[j]...

I personally suggest using using the second solution as it does not require the counter and it will break out of the loop at the first null position. If there is ever going to be a chance that there are null positions between non-null positions (caused by nulling or deleting a student at a specific position) I would suggest using the 'continue;' statement instead of the 'break;' statement as it will move to the next iteration.

Hope this helps.

-pH

stpatrck 15 Newbie Poster

If you use a 'foreach' or 'for' loop you can simply pass the values from the list. You don't need to create a new Student object in your display method. You also do not need to increment your iterator (i) within the for loop. The 'i++' part of the 'for' loop does this for you. Like ddanbe suggested, I would recommend a 'foreach' loop for your situation...

foreach(var student in _StudentList){
    richTextBox1.Text += "Student: " + student.Name + ...   
}

...but if you must use a simple 'for' loop...

for(int i = 0;i<_StudentList.Length;i++){
    richTextBox1.Text += "Student: " + _StudentList[i].Name + ...
}

You may want to review This MSDN Article about 'for' loops.

Hope this helps. :-)

-pH

stpatrck 15 Newbie Poster

As for creating a method to set the Candidate's name... You have a constructor that is assigning the 'name' via the 'anyName' param so you already have it. Simply remove the 'party' assignment, remove the 'anyParty' param from the method signature and change the method name to something like 'setName'.

Hope this helps. If so upvote. :-)
-pH

stpatrck 15 Newbie Poster

Check line 40. Compare it to line 51.

stpatrck 15 Newbie Poster

my mistake. the limit statement should be at the end of the query.

Try referring to This StackOverflow Question if it is still not working after moving the limit statement.

ravi142 commented: @Patrick: Thank You +0
stpatrck 15 Newbie Poster

try to order the results by the msg_id descending

something like...
select chat_msgs from user_chat where chat_from_id='2' and chat_to_id='10' limit 0,10 order by msg_id desc