Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 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 WindowsFormsApp2
  13. {
  14. public partial class Form1 : Form
  15. {
  16.  
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23. datagbehivs();
  24. }
  25. MySqlConnection csatlakozas = new MySqlConnection("datasource = localhost;port=3306;Initial Catalog='esemeny';username=root;password=");
  26. MySqlCommand parancs;
  27. private void datagbehivs()
  28. {
  29. string mysql = "SELECT*FROM napok";
  30. DataSet table = new DataSet();
  31. MySqlDataAdapter adapter = new MySqlDataAdapter(mysql, csatlakozas);
  32. adapter.Fill(table, "esemeny");
  33. dataGridView1.DataSource = table;
  34. dataGridView1.DataSource = table.Tables["esemeny"];
  35.  
  36. }
  37. public void nyitvacsatlakozas()
  38. {
  39. if (csatlakozas.State == ConnectionState.Closed)
  40. {
  41. csatlakozas.Open();
  42. }
  43. }
  44. public void zarvacsatlakozas()
  45. {
  46. if (csatlakozas.State == ConnectionState.Open)
  47. {
  48. csatlakozas.Close();
  49. }
  50. }
  51. public void textbehivas(string query)
  52. {
  53.  
  54. string mysql = ("SELECT*FROM napok");
  55. parancs = new MySqlCommand(mysql, csatlakozas);
  56. try
  57. {
  58. nyitvacsatlakozas();
  59. parancs = new MySqlCommand(query, csatlakozas);
  60. if (parancs.ExecuteNonQuery() == 1)
  61. {
  62. MessageBox.Show("sdsdssd");
  63. }
  64. else
  65. {
  66. MessageBox.Show("aaaaaaaaa");
  67. }
  68.  
  69. }
  70. catch (Exception ex)
  71. {
  72. MessageBox.Show(ex.Message);
  73.  
  74. }
  75. finally
  76. {
  77. zarvacsatlakozas();
  78. }
  79.  
  80. }
  81. private void button1_Click_1(object sender, EventArgs e)
  82. {
  83. datagbehivs();
  84. }
  85.  
  86. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  87. {
  88. textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
  89. textBox2.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
  90. textBox3.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
  91. }
  92.  
  93. private void button2_Click_1(object sender, EventArgs e)
  94. {
  95.  
  96. string add =" INSERT INTO `napok`(`id`, `fname`, `lastname`) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
  97. textbehivas(add);
  98. datagbehivs();
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement