D
David C
I have the following code in a asp.net web page that should always return a
single value (sum). Is there a better way to do this so I just get the
result and not have to check for HasRows, etc.? Also, I am thinking of
making this a stored proc when we go into production. If so, would the
"read" syntax be the same? Thanks.
David
'Get cost of parts sold this month for jobs completed
strSQL = "SELECT SUM(PartsCost) As TotalPartsCost" & _
" FROM dbo.vw_RORatesByPC" & _
" WHERE YEAR(RepairCompleteDate) = " & intYear.ToString & _
" AND MONTH(RepairCompleteDate) = " & intMonth.ToString
cmdSelect = New SqlCommand(strSQL, conData)
dtr = cmdSelect.ExecuteReader()
If dtr.HasRows Then
While dtr.Read()
If Not IsDBNull(dtr("TotalPartsCost")) Then
dblTotalCost = dtr("TotalPartsCost")
End If
Exit While
End While
End If
dtr.Close()
single value (sum). Is there a better way to do this so I just get the
result and not have to check for HasRows, etc.? Also, I am thinking of
making this a stored proc when we go into production. If so, would the
"read" syntax be the same? Thanks.
David
'Get cost of parts sold this month for jobs completed
strSQL = "SELECT SUM(PartsCost) As TotalPartsCost" & _
" FROM dbo.vw_RORatesByPC" & _
" WHERE YEAR(RepairCompleteDate) = " & intYear.ToString & _
" AND MONTH(RepairCompleteDate) = " & intMonth.ToString
cmdSelect = New SqlCommand(strSQL, conData)
dtr = cmdSelect.ExecuteReader()
If dtr.HasRows Then
While dtr.Read()
If Not IsDBNull(dtr("TotalPartsCost")) Then
dblTotalCost = dtr("TotalPartsCost")
End If
Exit While
End While
End If
dtr.Close()