I want to implement the function of selecting services from a list (listbox) and summing them. I ran into a problem. I will be glad of any help.
Example: Select services from the listbox ("chair(10), table(20)").When choosing the chair service, we specify the quantity for 1 day (for example, 1 chair), and the final amount (in the form of a text field) shows the price of a chair for 1 day (for 1 chair, the amount = 10).If you select the second service and delete the first service, the total amount will be displayed only for the selected service and vice versa.If none of the services is selected, then when you try to specify the number, the amount is 0 (because the service is not selected). When selecting several services, the amount of each service is summed up and displayed in the total amount.(Example: chair(10)+table(20)=total(30))
int Price Services = 0; -- it is necessary to sum up the cost of delivery + the cost of the service = the total amount of the order
int PriceServices = 0;
private void FetchCostServices()
{
if (listBox1.SelectedItems.Count == 0)
return;
string format = "SELECT ServicesCost FROM AdditionalServicesTbl WHERE ServicesNum in ({0})";
string values = string.Join(",", listBox1.SelectedItems.OfType<int>());
string query = string.Format(format, values);
var dt = new DataTable();
var sda = new SqlDataAdapter(query, Con);
sda.Fill(dt);
foreach (DataRow row in dt.Rows)
{
PriceServices += row.Field<int>("ServicesCost");
}
}
At the moment, this error occurs System.Data.SqlClient.SQLException: "Incorrect syntax next to ')'." in the line sda.Fill(dt);, when selecting the service variable of the query "SELECT ServicesCost FROM AdditionalServicesTbl, WHERE ServicesNum in ()" data type=DataRowView