Why doesn't the variable rise?



  • Hello.

    What's going on in this code is ID reading first, the request sorts it to increase... after which the ID transmits the variable timer. Next, looking for a URL field where ID = variable timer, it calculates and transmits URL to label1 and at the end, there is an increase in the variable timer to 1 so that the next time the timer reads not the same cell but the other.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;
    

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    public static string host, database, user, password, strProvider;
    public int timer = 0;

        public Form1()
        {
            InitializeComponent();
    
            host = "91.227.16.13";
            password = "15*35*";
            user = "h2*199_di*a";
            database = "h2*199_*est";
    
            strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Start();
        }
    
        private void timer1_Tick(object sender, EventArgs e)
        {
            MySqlConnection cnt = new MySqlConnection(strProvider);
            try
            {
                cnt.Open();
                MySqlCommand cmd3 = cnt.CreateCommand();
                MySqlCommand command = cnt.CreateCommand();
    
                command.CommandText = "SELECT * FROM t_links ORDER BY ID DESC";
    
                cmd3.CommandText = "SELECT * FROM t_links WHERE ID = " + timer;
    
                MySqlDataReader readID = command.ExecuteReader();
                while (readID.Read())
                {
                    timer = Convert.ToInt32(readID["ID"]);
                }
                readID.Close();
    
                MySqlDataReader readURK = cmd3.ExecuteReader();
                while (readURK.Read())
                {
                    label1.Text = "URL: " + readURK["URL"].ToString();
                }
                readURK.Close();
    
                this.Text = timer.ToString();
    
                timer++;
            }
            finally
            {
                cnt.Close();
            }
        }
    }
    

    }

    The program doesn't increase the variable... and it doesn't transfer URL to label1. Below the violin of the base where I try to take the meanings:

    alt text

    PS Yes, and tell me where the pictures are to be filled with pictures so that hexcode doesn't take them as a reference, but as a picture?



  •             command.CommandText = "SELECT * FROM t_links ORDER BY ID DESC"; // Команда на считывание всех записей из базы
    
                cmd3.CommandText = "SELECT * FROM t_links WHERE ID = " + timer;
    
                MySqlDataReader readID = command.ExecuteReader(); // Выполняем команду
                while (readID.Read())
                {
                    timer = Convert.ToInt32(readID["ID"]); // Присваиваем таймеру значение максимального id
                }
                readID.Close();
    

    timer = Convert.ToInt32(readID["ID"]); It occurs in every tick, so the timer may increase, but then, again, the maximum id is equal.

    using System;
    

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    public static string host, database, user, password, strProvider;
    public int timer = 0;
    MySqlConnection cnt;

        public Form1()
        {
            InitializeComponent();
    
            host = "11.111.11.11";
            password = "1111111111";
            user = "11111111111";
            database = "111111111111";
    
            strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
    
            cnt = new MySqlConnection(strProvider);
            cnt.Open();
            MySqlCommand command = cnt.CreateCommand();
            command.CommandText = "SELECT max(id) as `id` FROM t_links";
            timer = Convert.ToInt32(command.ExecuteScalar());
    
            timer1.Enabled = true;
            timer1.Start();
    
        }
    
        private void timer1_Tick(object sender, EventArgs e)
        {
    
            try
            {
                MySqlCommand cmd3 = cnt.CreateCommand();
    
                cmd3.CommandText = "SELECT * FROM t_links WHERE ID = " + timer;
    
                MySqlDataReader readURK = cmd3.ExecuteReader();
    
                while (readURK.Read())
                {
                    label1.Text = "URL: " + readURK["URL"].ToString();
                }
                readURK.Close();
    
                this.Text = timer.ToString();
    
                timer++;
            }
            finally
            {
                cnt.Close();
            }
        }
    }
    

    }

    Still, I can't figure out why to count the id footage more than the maximum. They're not there.

    Added:

    Then you better do it.

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    public static string host, database, user, password, strProvider;
    public int timer = 0;
    MySqlConnection cnt;
    MySqlDataReader readURK;

        public Form1()
        {
            InitializeComponent();
    
            host = "11.111.11.11";
            password = "1111111111";
            user = "11111111111";
            database = "111111111111";
    
            strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
    
            cnt = new MySqlConnection(strProvider);
            cnt.Open();
    
            MySqlCommand command = cnt.CreateCommand();
            command.CommandText = "SELECT * FROM t_links ORDER BY id";
            readURK = command.ExecuteReader();
    
            timer1.Enabled = true;
            timer1.Start();
    
        }
    
        private void timer1_Tick(object sender, EventArgs e)
        {
            if(readURK.Read())
            {
                label1.Text = "URL: " + readURK["URL"].ToString();
            }else{
                timer1.Stop();  // Стопим таймер когда записи закончились
            }
    
        }
    }
    

    }

    P.S., why did you publish your logs and passwords? :-




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2