0
This Datareader below when you type the product code it shows the name of the product in another textbox, works ok, but when instead of searching for the code search by the codebar it does not bring the name in the other textbox. Could someone please help.
string constring = @"Data Source=TI02;Initial Catalog=Loja;Integrated Security=True";
//string Query = "select * from produtos where codigo=' " + textBox1.Text + " ';"; //esse funciona
string Query = "select * from produtos where codigobarra=' " + textBox1.Text + " ';";// esse não funciona
SqlConnection conDataBase = new SqlConnection(constring);
SqlCommand cmdDataBase = new SqlCommand(Query, conDataBase);
SqlDataReader myReader;
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
string snome = myReader.GetString(myReader.GetOrdinal("nome")).ToString();
textBox2.Text = snome;
string sPreco = myReader.GetDecimal(myReader.GetOrdinal("preco")).ToString();
TextBoxValor.Text = sPreco;
}
Add more information: Are you getting any error code or just don’t show anything? Could you show us some table records to better understand? https://answall.com/help/minimal-reproducible-example
– Neto Costa
I managed to sort it out like this:
string campo;
 campo = textBox1.Text; 
 string Query = "select * from produtos where codigobarra='" + campo + "' ";
– Anderson Ricardo