Hi i'n trying to search a product name from database and display i ton my textbox but at same time i need the id from that product to insert it on grid and after on another table.
MySqlConnection connection = new MySqlConnection("connectonString");
string selectQuery = "select descricao,codigo from produtos where (barras = '@barcodes') or(descricao like '%' + @product + '%')";
connection.Open();
MySqlCommand command = new MySqlCommand(selectQuery, connection);
MySqlDataReader reader = command.ExecuteReader();
command.Parameters.AddWithValue("@barras", Txtcodigo.Text);
command.Parameters.AddWithValue("@product", Txtcodigo.Text);
//MySqlDataReader reader = command.ExecuteReader();
DataTable dt2 = new DataTable();
dt2.Load(reader);
DataView dvDataTable = new DataView(dt2);
//DataRow row = dt2.Rows[1];
Txtproduto.Text = reader.GetString("descricao");
It says my reader is empty but, i've used the same code to load combobox and it works, the only difference is that on combobox my select is: select * from unidades; and there re no parameters as there are only 2 rows on that table, and on products table there are more and i only need those 2: description and id; barcodes is just to search
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…