3 Replies - 771 Views - Last Post: 15 March 2012 - 01:20 PM Rate Topic: -----

#1 vbprotobe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-March 12

Quering a Sum() value from Access Database

Posted 15 March 2012 - 10:09 AM

hi,

Basically for normal select queries from my database I have no problems as I would put the following and then bind it to a controller to display the iteam, however now I am trying to query sum of a field from the database, but I think it should be different as It's giving a Nullable value:

SELECT SUM(PointsRedeemed) AS tAward
FROM [Transaction]
WHERE (BusinessId = ?) AND (CardNo = ?)


        Dim TransactionTableApt As New LoyaltyDataSetTableAdapters.TransactionTableAdapter
                TransactionTableApt.ScalartTotal(Login.lblHiddenBusId.Text, lblCardNo1.Text)
        lblPurValue.Text = LoyaltyDataSet.Card.Rows(0)("CustomerId")



Can anyone help by tellling what I am doing wrong?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Quering a Sum() value from Access Database

#2 vbprotobe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-March 12

Re: Quering a Sum() value from Access Database

Posted 15 March 2012 - 10:30 AM

View Postvbprotobe, on 15 March 2012 - 10:09 AM, said:

hi,

Basically for normal select queries from my database I have no problems as I would put the following and then bind it to a controller to display the iteam, however now I am trying to query sum of a field from the database, but I think it should be different as It's giving a Nullable value:

SELECT SUM(PointsRedeemed) AS tAward
FROM [Transaction]
WHERE (BusinessId = ?) AND (CardNo = ?)


        Dim TransactionTableApt As New LoyaltyDataSetTableAdapters.TransactionTableAdapter
                TransactionTableApt.ScalartTotal(Login.lblHiddenBusId.Text, lblCardNo1.Text)
        lblPurValue.Text = LoyaltyDataSet.Card.Rows(0)("CustomerId")



Can anyone help by tellling what I am doing wrong?

Thanks


Sorry the correct code is:

And it says no records at position 0

SELECT SUM(PointsRedeemed) AS tValue
FROM [Transaction]
WHERE (BusinessId = ?) AND (CardNo = ?)

Dim TransactionTableApt As New LoyaltyDataSetTableAdapters.TransactionTableAdapter
        TransactionTableApt.ClearBeforeFill = True
        TransactionTableApt.ScalartTotal(Login.lblHiddenBusId.Text, lblCardNo1.Text)
        lblPurValue.Text = LoyaltyDataSet.Transaction.Rows(0)("tValue")


Was This Post Helpful? 0
  • +
  • -

#3 vbprotobe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-March 12

Re: Quering a Sum() value from Access Database

Posted 15 March 2012 - 11:10 AM

I also tried the below code which I managed to get from msdn website:
        Dim TransactionTableApt As New LoyaltyDataSetTableAdapters.TransactionTableAdapter
        TransactionTableApt.ClearBeforeFill = True
        Dim returnValue As Integer
        returnValue = CType(TransactionTableApt.ScalartTotal(Login.lblHiddenBusId.Text, lblCardNo1.Text), Integer)
        lblPurValue.Text = returnValue


it says nullable object must have a value
Was This Post Helpful? 0
  • +
  • -

#4 vbprotobe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-March 12

Re: Quering a Sum() value from Access Database

Posted 15 March 2012 - 01:20 PM

View Postvbprotobe, on 15 March 2012 - 11:10 AM, said:

I also tried the below code which I managed to get from msdn website:
        Dim TransactionTableApt As New LoyaltyDataSetTableAdapters.TransactionTableAdapter
        TransactionTableApt.ClearBeforeFill = True
        Dim returnValue As Integer
        returnValue = CType(TransactionTableApt.ScalartTotal(Login.lblHiddenBusId.Text, lblCardNo1.Text), Integer)
        lblPurValue.Text = returnValue


it says nullable object must have a value


Hi All,

I believe i wasnt handling a null exception in this case, the above code seems to be alright.

apologies if it took ur time, i had to introduce a null exception if statement and that solved the issue.

kind Regards
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1