CONEXION SQL Y C#

Опубликовано: 25 Май 2026
на канале: gricelda gualavisi
22
1

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

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

private void btnconectar_Click(object sender, EventArgs e)
{
string servidor = txtservidor.Text;
string puerto = txtpuerto.Text;
string usuario = txtusuario.Text;
string password = txtpasword.Text;

string datos = "";

string cadenaconexion = "server=" + servidor + ";port=" + puerto + "; user id=" + usuario + "; password=" + password + ";database = world ";

MySqlConnection connexionBD = new MySqlConnection(cadenaconexion);

try
{
connexionBD.Open();
MySqlDataReader reader = null;
MySqlCommand cmd = new MySqlCommand("show tables",connexionBD);
reader = cmd.ExecuteReader();
while(reader.Read())
{
datos += reader.GetString(0)+"\n";
}
}
catch(MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show(datos);
}

private void btnsalir_Click(object sender, EventArgs e)
{
Close();
}

private void txtpasword_TextChanged(object sender, EventArgs e)
{

}
}
}