Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace Exercicio1
  13. {
  14. public partial class Form1 : Form
  15. {
  16. MySqlConnection cnn = new MySqlConnection();
  17. MySqlCommand cmd = new MySqlCommand();
  18. MySqlDataReader dr;
  19.  
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24.  
  25. private void label2_Click(object sender, EventArgs e)
  26. {
  27.  
  28. }
  29.  
  30. private void Form1_Load(object sender, EventArgs e)
  31. {
  32. cnn.ConnectionString = "server = localhost; user id=root;password=usbw;database=exercicio1;port=3307";
  33. cnn.Open();
  34.  
  35. cmd.CommandText = "select * from aluno";
  36. cmd.Connection = cnn;
  37. //cmd = new MysqlCommand("select * from aluno", cnn);
  38. dr = cmd.ExecuteReader();
  39. dr.Read();
  40.  
  41. textBox1.Text = dr[0].ToString();
  42. textBox2.Text = dr[1].ToString();
  43.  
  44. }
  45.  
  46. private void button1_Click(object sender, EventArgs e)
  47. {
  48. dr.Read();
  49.  
  50. textBox1.Text = dr[0].ToString();
  51. textBox2.Text = dr[1].ToString();
  52. }
  53.  
  54. private void textBox2_TextChanged(object sender, EventArgs e)
  55. {
  56.  
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement