-1
Hello, I have a problem, I enter the following problem: When I enter the data in the datagridview it does not "pull" from the database the information to put on the screen. BD is Mysql, Localhost and Naum has errors. Follow the code:
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 SistemaVendas
{
public partial class Caixa : Form
{
public Caixa()
{
InitializeComponent();
}
int precototal = 0;
MySqlConnection con = new MySqlConnection("server=localhost; database=sistemacsharp; username=root; password=");
private void txtnumprod_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar==13)
{
txtquantidade.Enabled = true;
txtquantidade.Focus();
}
}
private void txtquantidade_KeyPress(object sender, KeyPressEventArgs e)
{
txtnumprod.Clear();
txtquantidade.Clear();
try
{
string txt = "SELECT * FROM produtos WHERE ID='" + txtnumprod + "'";
MySqlCommand cmd = new MySqlCommand(txt, con);
con.Open();
MySqlDataReader r = cmd.ExecuteReader();
while (r.Read())
{
int preco = int.Parse(txtquantidade.Text.ToString()) * int.Parse(r[6].ToString());
precototal = preco;
dataGridView1.Rows.Insert(dataGridView1.RowCount, r[0], r[1], txtquantidade.Text.Trim(), r[6], preco);
}
lbltotalitens.Text = "" + (dataGridView1.RowCount - 1) + "";
lbltotal.Text = "" + precototal + "";
con.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message,"Este É Um Erro Vindo Do Banco de Dados");
}
txtnumprod.Focus();
txtnumprod.Clear();
txtquantidade.Enabled = false;
txtquantidade.Clear();
}
}
}
when pressing a key in the quantity field, the first thing it does is clear the field?!
– Rovann Linhalis