Results 1 to 3 of 3

Thread: [RESOLVED] Compacting Row.HasVersion(DataRowVersion.Proposed) use?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Resolved [RESOLVED] Compacting Row.HasVersion(DataRowVersion.Proposed) use?

    Is there a way to do the following in a single statement?

    Code:
    If e.Row.HasVersion(DataRowVersion.Proposed) Then
        Debug.WriteLine("Proposed = " & e.Row.HasVersion(DataRowVersion.Proposed).ToString)
    Else
        Debug.WriteLine("Proposed = Nothing")
    End If
    I thought an IIF statement would do the trick, but it throws a System.Data.VersionNotFoundException exception because IIf always evaluates both truepart and falsepart (even though it returns only one of them).

    Code:
    Debug.WriteLine("Proposed = " & IIf(e.Row.HasVersion(DataRowVersion.Proposed), e.Row.Item(col, DataRowVersion.Proposed), "Nothing").ToString)

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Compacting Row.HasVersion(DataRowVersion.Proposed) use?

    In modern versions of VB you don't need to use IIF, you can use IF in the same way instead:
    Code:
    Debug.WriteLine("Proposed = " & If(e.Row.HasVersion(DataRowVersion.Proposed), e.Row.Item(col, DataRowVersion.Proposed), "Nothing").ToString)
    This has the benefit of not evaluating all parts, thus not causing the issue you are having (and it also runs a little faster, which helps in some situations).

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: Compacting Row.HasVersion(DataRowVersion.Proposed) use?

    si -

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width