Advertisement
Guest User

Untitled

a guest
Jun 6th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1.  foreach (DataGridViewRow Datarow in dataGridView2.Rows)
  2.             {
  3.                 if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null)
  4.                 {
  5.                      string contentValue1 = Datarow.Cells[0].Value.ToString();
  6.                     MessageBox.Show(contentValue1);
  7.                     string query = $@"SELECT AVG(Price/Number_of_Products)
  8.                                      From Products_in_Check JOIN Product
  9.                                      ON Products_in_Check.Product_Code = Product.Product_Code
  10.                                      WHERE Product.Product_Name = {contentValue1}";
  11.                     string connection_str = @"Data Source = .\SERVERBOGOV; Initial Catalog = beershopbd; Integrated Security = True";
  12.                     using (SqlConnection connection = new SqlConnection(connection_str))
  13.                     {
  14.                         connection.Open();
  15.                         SqlCommand command = new SqlCommand(query, connection);
  16.                         SqlDataReader reader = command.ExecuteReader();
  17.                         if (reader.HasRows)
  18.                         {
  19.                             while (reader.Read())
  20.                             {
  21.                                 object temp_price = reader.GetValue(0);
  22.                                 check = check + (float)temp_price;
  23.                             }
  24.                         }
  25.                        
  26.                     }
  27.                 }
  28.  
  29.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement