title: How to Compute a Database Column in .NET
body: <p>I have a Database named CarsType.accdb there are four fields in the data base Item_Name, Item_Num, Item_Qty, Item_Cost.  </p>
  
  <p>I am able to get the database to display my data in VisualBasic but I am not sure how to get the total cost to appear in my label (lblTotalCost).  I prefer doing it in VB versus writing in my access program.  All I am wanting to do it multiply <code>item_qty * Item_Cost</code>  How would I go about doing that?</p>
  
  <pre><code>Public Class frmCarInventory
  
      Private Sub CarInventoryBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CarInventoryBindingNavigatorSaveItem.Click
          Me.Validate()
          Me.CarInventoryBindingSource.EndEdit()
          Me.TableAdapterManager.UpdateAll(Me.CarDataSet)
  
      End Sub
  
      Private Sub frmCarInventory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          'TODO: This line of code loads data into the 'CarDataSet.CarInventory' table. You can move, or remove it, as needed.
          Me.CarInventoryTableAdapter.Fill(Me.CarDataSet.CarInventory)
  
  
          Try
              Me.CarInventoryTableAdapter.Fill(Me.CarDataSet.CarInventory)
          Catch ex As Exception
              MsgBox("The Database Files is Unavailable", , "Error")
          End Try
  
  
  
      End Sub
  
      Private Sub btnComputeTheTotalValueOfInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComputeTheTotalValueOfInventory.Click
  
  
          Dim strSql As String = "SELECT * FROM CarType "
  
          'strPath provides the database type and path of the CarType database.
          Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" &amp; "Data Source=..\CarType.accdb"
          Dim odaInventory As New OleDb.OleDbDataAdapter(strSql, strPath)
          Dim DatCost As New DataTable
          Dim intCount As Integer
          Dim decTotalCost As Decimal = 0D
  
          'The DataTable name datCost is filled with the data
      odaInventory.Fill(DatCost)
  
          'The connection to the databsise is disconnected
          odaInventory.Dispose()
  
          For intCount = 0 To DatCost.Rows.Count - 1
              decTotalCost += Convert.ToDecimal(DatCost.Rows(intCount)("Total Inventory  Cost"))
          Next
  
          Me.lblTotalCost.Visible = True
          Me.lblTotalCost.Text = "El Value " &amp; decTotalCost.ToString("C")
  
      End Sub
  End Class
  </code></pre>
  
  <p>Would this be handled like an sql satement?</p>