using System; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace MySQLasync { public partial class Form1 : Form { // public variables and constants string strconnect = "Server = localhost; Port=3306; Database=mydbase; Uid=myusername; Pwd=mypasswd;"; Random r = new Random(); int c = 0; public Form1() { InitializeComponent(); } private void Button1_Click(object sender, EventArgs e) { timer1.Enabled = true; GetData(); } private async void GetData() { listBox1.Items.Clear(); string sql = "SELECT * FROM websites"; MySqlConnection con1 = new MySqlConnection(strconnect); { con1.Open(); MySqlCommand cmd = new MySqlCommand(sql, con1); MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync(); while (reader.Read()) { listBox1.Items.Add(reader["title"].ToString()); } con1.Close(); } } private void Timer1_Tick(object sender, EventArgs e) { c++; if (c > 20) { c = 0; listBox2.Items.Clear(); } int num = r.Next(1, 999999); listBox2.Items.Add(num); } } }
while (await reader.ReadAsync())
await conn.OpenAsync();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)