How can i read the return value from “Select Where” statement , every time i run no return value appear in the label, and no syntax error.
command.CommandText = "select product_price from product where product_name='"+x+"';";
connection.Open();
Reader = command.ExecuteReader();
while(Reader.Read()){
Price_label.Content = "" + Reader.GetString(0);
}
connection.Close();
If the
product_pricecolumn is not of typeTEXTin MySQL, theReader.GetString(0)will (depending on how the reader was implemented by Oracle) throw an Exception or return an empty string. I would think the latter is happening.Retrieving the value through a
DataReaderrequires you to know the data type. You can not simply read a string for every type of field. For example, if the field in the database is an Integer, you need to useGetInt32(...). If it is aDateTimeuseGetDateTime(...). UsingGetStringon aDateTimefield won’t work.EDIT
This is how I’d write this query: