Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.MySqlClient;
- namespace WindowsFormsApplication6
- {
- public partial class Form9 : Form
- {
- public Form9()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string cs = "data source=localhost; database=produtos; user id=root; pwd=''";
- MySqlConnection liga = new MySqlConnection(cs);
- string query = "update produto set quant= quant + ?m where cod=?n";
- try
- {
- MySqlCommand cmd = new MySqlCommand(query, liga);
- cmd.Parameters.AddWithValue("?n", textBox1.Text);
- cmd.Parameters.AddWithValue("?m", textBox2.Text);
- liga.Open();
- cmd.ExecuteNonQuery();
- }
- catch (MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- liga.Close();
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- string cs = "data source=localhost; database=produtos; user id=root; pwd=''";
- MySqlConnection liga = new MySqlConnection(cs);
- string query = "select * from produto where cod =?n";
- try
- {
- MySqlCommand cmd = new MySqlCommand(query, liga);
- cmd.Parameters.AddWithValue("?n", textBox1.Text);
- liga.Open();
- MySqlDataReader leitor = cmd.ExecuteReader();
- while (leitor.Read())
- {
- textBox1.Text = leitor.GetString("cod");
- textBox2.Text = leitor.GetString("quant");
- }
- leitor.Close();
- }
- catch (MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- liga.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement