I try to catch the end of the rows in the table, but the condition does not pass. How can you intercept this situation? Occurs in the if(CounterQuestion>CounterCycle) line if(CounterQuestion>CounterCycle)
using System; using System.Data; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace TestingPerson { class DataBaseMysql : IDataBase { MySqlConnectionStringBuilder objMysqlConnStrBuild; MySqlConnection mysqlConnect; MySqlConnectionStringBuilder mysqlBuilder = new MySqlConnectionStringBuilder(); MySqlCommand mysqlCommand; MySqlDataAdapter dataAdapter; DataTable dt = new DataTable(); public string query { get; set; } public int CounterQuestion = 0; int CounterReceive = 0; private int[] pointsAnswers; private int TotalSum; bool IsGetTime; public DataBaseMysql() { IsGetTime = false; pointsAnswers = new int[5]; } /// <summary> /// Установление соединения с базой данных /// </summary> /// <param name="objMysqlConnStrBuild">объект для хранения строки подключения</param> /// <param name="objMode">Режим подключения</param> /// <param name="hostname">IP хоста</param> /// <param name="password">Пароль(если нужен)</param> /// <param name="username">Логин для подключения</param> /// <param name="dbname">Название базы данных</param> /// <param name="port">Порт</param> /// <returns></returns> public object InstallPropertyConnect(MySqlConnectionStringBuilder objMysqlConnStrBuild, MySqlSslMode objMode, string hostname, string password, string username, string dbname, uint port) { objMysqlConnStrBuild = new MySqlConnectionStringBuilder(); objMysqlConnStrBuild.Server = hostname; objMysqlConnStrBuild.UserID = username; objMysqlConnStrBuild.Password = password; objMysqlConnStrBuild.Database = dbname; objMysqlConnStrBuild.Port = port; objMysqlConnStrBuild.SslMode = objMode; mysqlBuilder = objMysqlConnStrBuild; return mysqlBuilder; } /// <summary> /// Получение данных для локальной таблицы /// </summary> /// <param name="objMysqlConn"></param> /// <param name="objMysqlConnStrBuild"></param> /// <param name="objMysqlComm"></param> /// <param name="objMysqlDataAdapt"></param> /// <param name="objdatatable"></param> /// <param name="Query"></param> /// <returns></returns> public void ReceiveData() { mysqlBuilder = (MySqlConnectionStringBuilder)InstallPropertyConnect(mysqlBuilder, MySqlSslMode.None, "localhost", "", "root", "testingpeople", 3306); try { query = "SELECT * FROM questiontable"; mysqlConnect = new MySqlConnection(mysqlBuilder.ConnectionString); mysqlCommand = new MySqlCommand(query, mysqlConnect); dataAdapter = new MySqlDataAdapter(mysqlCommand); mysqlConnect.Open(); dataAdapter.Fill(dt); dataAdapter.Dispose(); mysqlConnect.Close(); } catch (MySqlException ex) { MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }//Функция получения данных из бд и заполнения локальной таблицы /// <summary> /// Заполнение данных на форме /// </summary> /// <param name="Question">Label для хранения вопроса</param> /// <param name="Answer1">Label для хранения первого ответа</param> /// <param name="Answer2">Label для хранения второго ответа</param> /// <param name="Answer3">Label для хранения третьего ответа</param> /// <param name="Answer4">Label для хранения четвертого ответа</param> /// <param name="Answer5">Label для хранения пятого ответа</param> /// <param name="countTime">Label для хранения времени на тест</param> public object FillTable(Label[] labels, CheckBox[] checkboxes, Panel[] panels) { InstallPropertyConnect(objMysqlConnStrBuild, MySqlSslMode.None, "localhost", "", "root", "testingpeople", 3306); if (CounterReceive == 0) { ReceiveData(); CounterReceive++; } else { if (this.TotalSum <= 0) { int index = 0; foreach (CheckBox a in checkboxes) { if (a.Checked == true) { TotalSum += pointsAnswers[index]; } index++; } } foreach (CheckBox a in checkboxes) { a.Checked = false; } try { int CounterCycle = dt.Rows.Count;//Переменная для подсчета количества вопрос, для дальнейшей сверки if (dt.Rows.Count == 0) { MessageBox.Show("Отсутсвуют данные в базе!"); } else { if(CounterQuestion>CounterCycle) { MessageBox.Show("Тест закончен!, итоговое количество баллов = '" + pointsAnswers + "'"); } else { labels[0].Text = dt.Rows[this.CounterQuestion]["Question"].ToString(); labels[1].Text = dt.Rows[this.CounterQuestion]["Answer1"].ToString(); pointsAnswers[0] = Convert.ToInt32(dt.Rows[this.CounterQuestion]["CountPointAnswer1"].ToString()); labels[2].Text = dt.Rows[this.CounterQuestion]["Answer2"].ToString(); pointsAnswers[1] = Convert.ToInt32(dt.Rows[this.CounterQuestion]["CountPointAnswer2"].ToString()); if (dt.Rows[this.CounterQuestion]["Answer3"].ToString() == "") { checkboxes[2].Hide(); labels[3].Hide(); panels[2].Hide(); checkboxes[3].Hide(); labels[4].Hide(); panels[3].Hide(); checkboxes[4].Hide(); labels[5].Hide(); panels[4].Hide(); } else { checkboxes[2].Show(); labels[3].Show(); panels[2].Show(); labels[3].Text = dt.Rows[this.CounterQuestion]["Answer3"].ToString(); pointsAnswers[2] = Convert.ToInt32(dt.Rows[this.CounterQuestion]["CountPointAnswer3"].ToString()); if (dt.Rows[this.CounterQuestion]["Answer4"].ToString() == "") { checkboxes[3].Hide(); labels[4].Hide(); panels[3].Hide(); } else { checkboxes[3].Show(); labels[4].Show(); panels[3].Show(); labels[4].Text = dt.Rows[this.CounterQuestion]["Answer4"].ToString(); pointsAnswers[3] = Convert.ToInt32(dt.Rows[this.CounterQuestion]["CountPointAnswer4"].ToString()); if (dt.Rows[this.CounterQuestion]["Answer5"].ToString() == "") { checkboxes[4].Hide(); labels[5].Hide(); panels[4].Hide(); } else { checkboxes[4].Show(); labels[5].Show(); panels[4].Show(); labels[5].Text = dt.Rows[this.CounterQuestion]["Answer5"].ToString(); pointsAnswers[4] = Convert.ToInt32(dt.Rows[this.CounterQuestion]["CountPointAnswer5"].ToString()); } } } } } if (IsGetTime == false) { // Form1.TimeM = (Int32)dt.Rows[0]["CountTime"]; } } catch (MySqlException ex) { MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } CounterQuestion++; } return dt; } public void StartTimer(Timer timer1) { } /// <summary> /// Перемешивание вопросов /// </summary>s public void MixQuestion() { } public void Autorize() { } } }
if(CounterQuestion>CounterCycle)? In the same place two inta are compared to each other ?! You set a breakpoint at the entrance to theFillTable()method (place the cursor on the line and press F9), check which values of the method parameters and if everything is OK press F10 move on, look at which line the error occurs, look at the values of all variables and find what is wrong . - Bulson