Good evening community, I have a stock program that I'm finishing and I want to do a validation for it always check if you have enough of that product before adding it to the sale. For this I used a simple math operation, where one variable stores the requested value, another the value that exists in the database and then a third variable stores the subtraction of them and tests an if. However I am having difficulty storing the Select result in the variable, is there any command to get the value of a table cell or something like that? below is the code
Code:
private void btAddProd_Click(object sender, EventArgs e)
{
DataTable tabela = new DataTable();
DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao);
var cod = Convert.ToString(txtProCod.Text);
SqlDataAdapter da = new SqlDataAdapter("Select pro_qtde from produto where pro_cod like '%" + cod + "%' ", cx.StringConexao);
da.Fill(tabela);
double testeqtde = 0;
double estoqueqtde = 0;
double testetotal = 0;
testeqtde = Convert.ToDouble(txtQtde.Text);
estoqueqtde = Convert.ToDouble(tabela.Rows[0]);
testetotal = estoqueqtde - testeqtde;
if (testetotal < 0)
{
MessageBox.Show("Não há quantidade o bastante no estoque! Quantidade:" + estoqueqtde);
}
else
{
if ((txtProCod.Text != "") && (txtQtde.Text != "") && (txtValor.Text != ""))
{
Double TotalLocal = Convert.ToDouble(txtQtde.Text) * Convert.ToDouble(txtValor.Text);//metodo para calcular o total do produto
this.totalVenda = this.totalVenda + TotalLocal;//metodo para somar o total da compra
String[] i = new String[] { txtProCod.Text, lProduto.Text, txtQtde.Text, txtValor.Text, TotalLocal.ToString() };//criado vetor de string
this.dgvItens.Rows.Add(i);//adicionando o string dentro da datagrid
txtProCod.Clear();//limpar o campo
lProduto.Text = "Informe o código do produto ou clique em localizar";
txtQtde.Clear();//limpar o campo
txtValor.Clear();//limpar o campo
txtTotalVenda.Text = this.totalVenda.ToString();//atualizar o total da compra
}
}
}
The problem really is there in the stockqtde, I do not know which command to use to get the only value that has inside the table that is the pro_qtde of the product being requested.