Reputation: 65
My drop down list contain Category items from database, so when l select any item it should display its total from the database to card or label. For instance the drop down list is loaded and the card displays total sum value for all category, so l want when l select a category let say Tools then it should display the total quantity for only Tools in the card. It been days l cannot seem to solve this. Kindly assist.
My requirement is to display from the database to card whenever drop down value change.
public decimal TodtalValue()
{
var query = "Select Sum(Quantity) AS Totalunit From OrderDetail Where Category = @Category ";
string sqlDataSource = _configuration.GetConnectionString("DefaultConnection");
decimal total = 0;
string value = "Category";
using (SqlConnection con = new SqlConnection(sqlDataSource))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@Category", value);
using (SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.HasRows && dr.Read())
{
if (!dr.IsDBNull(0))
{
total = dr.GetDecimal(0);
}
}
}
}
con.Close();
}
return total;
}
Upvotes: 0
Views: 63