Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 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 WindowsFormsApplication6
  13. {
  14. public partial class Form9 : Form
  15. {
  16. public Form9()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void button1_Click(object sender, EventArgs e)
  22. {
  23. string cs = "data source=localhost; database=produtos; user id=root; pwd=''";
  24. MySqlConnection liga = new MySqlConnection(cs);
  25.  
  26. string query = "update produto set quant= quant + ?m where cod=?n";
  27. try
  28. {
  29. MySqlCommand cmd = new MySqlCommand(query, liga);
  30. cmd.Parameters.AddWithValue("?n", textBox1.Text);
  31. cmd.Parameters.AddWithValue("?m", textBox2.Text);
  32. liga.Open();
  33. cmd.ExecuteNonQuery();
  34. }
  35. catch (MySqlException ex)
  36. {
  37. MessageBox.Show(ex.Message);
  38. }
  39.  
  40. finally
  41. {
  42. liga.Close();
  43. }
  44. }
  45.  
  46. private void button3_Click(object sender, EventArgs e)
  47. {
  48. string cs = "data source=localhost; database=produtos; user id=root; pwd=''";
  49. MySqlConnection liga = new MySqlConnection(cs);
  50. string query = "select * from produto where cod =?n";
  51. try
  52. {
  53. MySqlCommand cmd = new MySqlCommand(query, liga);
  54. cmd.Parameters.AddWithValue("?n", textBox1.Text);
  55. liga.Open();
  56. MySqlDataReader leitor = cmd.ExecuteReader();
  57. while (leitor.Read())
  58. {
  59. textBox1.Text = leitor.GetString("cod");
  60. textBox2.Text = leitor.GetString("quant");
  61. }
  62. leitor.Close();
  63. }
  64. catch (MySqlException ex)
  65. {
  66. MessageBox.Show(ex.Message);
  67. }
  68. finally
  69. {
  70. liga.Close();
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement