Quantcast
Viewing all articles
Browse latest Browse all 3509

ExecuteScalar() gives error, what is wrong?

When I try to run this code I get the following error: An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

This is my code:

protected void ButtonAdd_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(strcon);
            string Id = DropDownListB.DataValueField;
            SqlCommand cmd = new SqlCommand("SELECT Price FROM BooksInfo WHERE ISBN No=@Id", con);
            cmd.Parameters.AddWithValue("@Id", Id);
            con.Open();
            string test = (String)cmd.ExecuteScalar();
            LabelQuantity.Text = test;
            con.Close();
        }


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>