0

I have a table by name assetcategory in database.I need the sum of quantity attribute where Asset_name attribute equal to CPU. After this i want to store the result in a label.

I wrote the following query but its not working.

  Dim cmd3 As New OleDbCommand("Select sum(Quantity) from assetcategory where ID ='A013' and Asset_Name='CPU'", con)     
  Dim dr1 As OleDbDataReader
  dr1 = cmd3.ExecuteReader
    While dr1.Read
      Label4.text=dr1.item(0).Tostring
    End While
Vikas Kunte
  • 683
  • 4
  • 15
  • 35

1 Answers1

0

This would happen if sum(Quantity) is NULL because no rows match

Community
  • 1
  • 1
gbn
  • 422,506
  • 82
  • 585
  • 676
  • hey..tat particular query is working in sql. But how to store that value in a variable using vb.net – Vikas Kunte Mar 23 '11 at 06:08
  • Dim cmd3 As New OleDbCommand("Select sum(Quantity) from assetcategory where ID ='A013' and Asset_Name='CPU'", con) Dim cpucount As Int32 cpucount = Convert.ToInt32(cmd1.ExecuteScalar()) lblcpu.Text = cpucount – Vikas Kunte Mar 23 '11 at 06:25
  • You are getting the Quantity columns for all rows in the assetcategory table with a certain ID and Asset_Name and then summing those values. There will only be one result. – Chris Dunaway Mar 23 '11 at 16:26