I tried this code to extract a single value from my database and store it in a variable. But it extracts the value Supplier ID
instead of Quantity
.
string query3 = "SELECT Quantity FROM Supplier WHERE [Supplier ID]='"+supplierid+"'";
SqlCommand cmd3 = new SqlCommand(query3, con);
con.Open();
string temporaryquantity = cmd.ExecuteScalar().ToString();
MessageBox.Show(temporaryquantity);
How can I extract Quantity
instead of Supplier ID
?
Your query will return the Quantity field... if you execute it . Your variable naming is unfortunate - you're creating cmd3
and executing cmd
.
Execute cmd3
, and your result will be as expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.