Reputation: 21
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
?
Upvotes: 0
Views: 777
Reputation: 4879
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.
Upvotes: 3