Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach (DataGridViewRow Datarow in dataGridView2.Rows)
- {
- if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null)
- {
- string contentValue1 = Datarow.Cells[0].Value.ToString();
- MessageBox.Show(contentValue1);
- string query = $@"SELECT AVG(Price/Number_of_Products)
- From Products_in_Check JOIN Product
- ON Products_in_Check.Product_Code = Product.Product_Code
- WHERE Product.Product_Name = {contentValue1}";
- string connection_str = @"Data Source = .\SERVERBOGOV; Initial Catalog = beershopbd; Integrated Security = True";
- using (SqlConnection connection = new SqlConnection(connection_str))
- {
- connection.Open();
- SqlCommand command = new SqlCommand(query, connection);
- SqlDataReader reader = command.ExecuteReader();
- if (reader.HasRows)
- {
- while (reader.Read())
- {
- object temp_price = reader.GetValue(0);
- check = check + (float)temp_price;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement