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; using MySql.Data; using MySql.Data.MySqlClient; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public MySqlConnection connect = new MySqlConnection("Server=localhost;Database=dbuser;Uid=root;Pwd='';"); private void button1_Click(object sender, EventArgs e) { connect.Open(); try { string t1 = textBox1.Text; string t2 = textBox2.Text; string ekle = "insert into users(username,upassword) values('" + t1 + "','" + t2 + "')"; MySqlCommand cmdcommand = new MySqlCommand(ekle, connect); cmdcommand.ExecuteReader(); MessageBox.Show("Kayıt Yapıldı"); connect.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void Form1_Load(object sender, EventArgs e) { MySqlCommand komut = new MySqlCommand("SELECT * from users", connect); MySqlDataAdapter da = new MySqlDataAdapter(komut); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; connect.Close(); } private void button2_Click(object sender, EventArgs e) { MySqlCommand komut = new MySqlCommand("SELECT * from users", connect); MySqlDataAdapter da = new MySqlDataAdapter(komut); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; connect.Close(); string veri1 = textBox1.Text; string veri2 = textBox2.Text; textBox1.Text = veri1; textBox2.Text = veri2; } } }