mysql

 avatar
user_8607526207
csharp
2 years ago
1.7 kB
4
Indexable
Never
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql;
using MySql.Data.MySqlClient;

namespace MYSQL
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strconn = "Server = 149.28.22.147; Database = test; UId = tien; Pwd = FqK2Br4z4xCFflzsv; Pooling=false;Character Set=utf8";
            
            try
            {

                MySqlConnection conn = new MySqlConnection(strconn);
                conn.Open();
                
                string sql = "Select id, command from demo ";
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;
                cmd.CommandText = sql;
                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    if(reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            label1.Text = reader.GetString(1);
                        }
                    }
                    else
                    { 
                        label1.Text = "khong co du lieu";
                    }
                }
            }
            catch (Exception)
            { 
                MessageBox.Show("Test");
                throw;
            }
    
        }
    }
}