none
Max Value RRS feed

  • Question

  • Hello friends,

    I'm trying to get the max value of BillNumber column by using the following

    Dim

    db As New CLRNA.DCRNADataContext()

     

    Dim MaxBillNumber As Integer = db.Bills.Where(Function(sc) sc.ClientID = Convert.ToInt32(HiddenClientID.Value)).[Select](Function(sc1) If(DirectCast(sc1.BillNumber, System.Nullable(Of Integer)), 0)).Max()

     

    the problem is when the table bills is empty is receive an error,  how do i set the max value to zero when no records are returned?

     

    Regards

    Mike

    Saturday, November 19, 2011 10:04 AM

Answers

  • Hi MikeJH73,

    You can check whether the table is null before get data from it. db.Bills.First() to get the first element of the sequence, if is is null, set the max to 0, if it is not null, write the code as you have done in the post.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Monday, November 21, 2011 9:01 AM
    Moderator

All replies

  • Hi MikeJH73,

    You can check whether the table is null before get data from it. db.Bills.First() to get the first element of the sequence, if is is null, set the max to 0, if it is not null, write the code as you have done in the post.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Monday, November 21, 2011 9:01 AM
    Moderator
  • Hi MikeJH73,

    I marked my reply as answer, if you have any problem, please feel free to let me know.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Friday, November 25, 2011 1:46 AM
    Moderator