Hello.

What happens in this code, first the ID is read, the request sorts them by increment ... after which the ID is passed to the timer variable. Then another query looks for the URL field where ID is the timer variable, it reads and passes the URL to label1, and at the very end, the timer variable is incremented by 1, so that the next time the timer is accessed, it’s not the same cell but another one.

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 does not increment the variable ... and does not pass the URL to label1. Below is a screenshot of the database where I'm trying to get the values:

alt text

PS Yes, and tell me, on which hosting of images it is necessary to upload pictures so that the hashcode is not perceived as a link, but as a picture?

  • one
    To insert a picture, use the insert button in the editor. - Nicolas Chabanovsky ♦

1 answer 1

  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 happens at every tick, so the timer may increase and then again set to the maximum id.

 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(); } } } } 

But all the same, I cannot understand why reading from the database records with id greater than the maximum. They are not there :-)

Added:

Then do it better

 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(); // Π‘Ρ‚ΠΎΠΏΠΈΠΌ Ρ‚Π°ΠΉΠΌΠ΅Ρ€ ΠΊΠΎΠ³Π΄Π° записи Π·Π°ΠΊΠΎΠ½Ρ‡ΠΈΠ»ΠΈΡΡŒ } } } } 

PS Why did you publish your logins and passwords? :-)

  • The program should work on the principle of auto-surfing, considered the ID to transfer its label, then waited for the timer interval, again considered but not the one that was before, but the one that was before + 1. Well, as I was told, I am reading the smallest ID , and the program should gradually (according to the timer operation) reach the maximum ID - Angus123
  • Well, then command.CommandText = "SELECT min (id) as id FROM t_links"; order by then I bent a little, right now correct. - mantigatos
  • HOORAY!! EVERYTHING IS WORKING!!!! IF YOU WOULD KNOW HOW MUCH I TRIED TO CORRECT THE ERROR ... tell me what you replaced (I want to understand ..) Read the first post, I painted the data. - Angus123
  • And here's another question, look at the table, there is a pass there ... ID 77 then immediately goes 79 .. how to proceed in this case? To prog jump to 80? - Angus123
  • Use the code from the augmented answer. It simply bypasses the available lines without unnecessary requests to the database. Everything is much easier there. - mantigatos