Advertisement
Guest User

Untitled

a guest
Apr 9th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using MySql.Data;
  11. using MySql.Data.MySqlClient;
  12. namespace MySqlDataGridView
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.             string server;
  23.             string database;
  24.             string uid;
  25.             string password;
  26.             server = "localhost";
  27.             database = "ecommerce";
  28.             uid = "root";
  29.             password = "";
  30.             string connectionString;
  31.             connectionString = "SERVER=" + server + ";" + "DATABASE=" +
  32.             database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
  33.  
  34.             MySqlConnection con = new MySqlConnection(connectionString);
  35.             con.Open();
  36.             string query = "SELECT * FROM catalog";
  37.             MySqlCommand cmd = new MySqlCommand(query, con);
  38.             MySqlDataReader dr = cmd.ExecuteReader();
  39.             BindingSource bs = new BindingSource();
  40.             bs.DataSource = dr;
  41.             dataGridView1.DataSource = bs;
  42.             con.Close();
  43.  
  44.         }      
  45.  
  46.        
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement