Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. vb.net, select where statement

vb.net, select where statement

Scheduled Pinned Locked Moved Database
csharphelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    I don't seem to be getting this right in VB. I get an error in casting the result as an Integer, in which the result may not exist. ProductInfo_Inventory should be a join to get a count

    Dim cStatus As Integer = context.ProductInfo_Inventory.Where(Function(m) m.partNumber = p_PartNumber).Select(Function(m) m.currentStatus).DefaultIfEmpty()

    This is the whole thing. Not every item has a record in inventory for it's optional. So I'm not really sure how to properly handle this in VB My new program is much better and in c#, so I seem to be doing better in that now.

    pValue = context.ProductInfo.Where(Function(m) m.PartNumber = p_PartNumber).Count()
    Dim cStatus = context.ProductInfo_Inventory.Where(Function(m) m.partNumber = p_PartNumber).Select(Function(m) m.currentStatus).DefaultIfEmpty()
    If (cStatus = 4) Then
    dV = False
    Else
    dV = If(pValue > 0, True, False)
    End If

    21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.

    W 1 Reply Last reply
    0
    • J jkirkerx

      I don't seem to be getting this right in VB. I get an error in casting the result as an Integer, in which the result may not exist. ProductInfo_Inventory should be a join to get a count

      Dim cStatus As Integer = context.ProductInfo_Inventory.Where(Function(m) m.partNumber = p_PartNumber).Select(Function(m) m.currentStatus).DefaultIfEmpty()

      This is the whole thing. Not every item has a record in inventory for it's optional. So I'm not really sure how to properly handle this in VB My new program is much better and in c#, so I seem to be doing better in that now.

      pValue = context.ProductInfo.Where(Function(m) m.PartNumber = p_PartNumber).Count()
      Dim cStatus = context.ProductInfo_Inventory.Where(Function(m) m.partNumber = p_PartNumber).Select(Function(m) m.currentStatus).DefaultIfEmpty()
      If (cStatus = 4) Then
      dV = False
      Else
      dV = If(pValue > 0, True, False)
      End If

      21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      The first question is, what is the type of currentStatus?. If it's non-numeric or beyond the limits of integer, the cast will fail. Another thing is that if the current status is nullable (or reference type) then the default would be null which cannot be cast to integer. The most accurate information is in the error message, but you didn't post that.

      J 1 Reply Last reply
      0
      • W Wendelius

        The first question is, what is the type of currentStatus?. If it's non-numeric or beyond the limits of integer, the cast will fail. Another thing is that if the current status is nullable (or reference type) then the default would be null which cannot be cast to integer. The most accurate information is in the error message, but you didn't post that.

        J Offline
        J Offline
        jkirkerx
        wrote on last edited by
        #3

        I had a customer walk in while posting and I hit post without much details, sorry about that; my bad. This just determines if an item really exist, in case someone messed with the query string and put bad chars in there, or if an item was marked for deletion. I went with this; cStatus is an Integer.

        pValue = context.ProductInfo.Where(Function(m) m.PartNumber = p_PartNumber).Count()
        If (context.ProductInfo_Inventory.Any(Function(m) m.partNumber = p_PartNumber)) Then
        cStatus = context.ProductInfo_Inventory.Where(Function(m) m.partNumber = p_PartNumber).Select(Function(m) m.currentStatus).FirstOrDefault()
        End If

        If (cStatus = 4) Then
        dV = False
        Else
        dV = If(pValue < 4, True, False)
        End If

        21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.

        W 1 Reply Last reply
        0
        • J jkirkerx

          I had a customer walk in while posting and I hit post without much details, sorry about that; my bad. This just determines if an item really exist, in case someone messed with the query string and put bad chars in there, or if an item was marked for deletion. I went with this; cStatus is an Integer.

          pValue = context.ProductInfo.Where(Function(m) m.PartNumber = p_PartNumber).Count()
          If (context.ProductInfo_Inventory.Any(Function(m) m.partNumber = p_PartNumber)) Then
          cStatus = context.ProductInfo_Inventory.Where(Function(m) m.partNumber = p_PartNumber).Select(Function(m) m.currentStatus).FirstOrDefault()
          End If

          If (cStatus = 4) Then
          dV = False
          Else
          dV = If(pValue < 4, True, False)
          End If

          21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          No problem! So everything works now? Just notice that FirstOrDefault may also return null which wuold cause an exception since cStatus is integer so depending on the situation you may want to use integer? and check if a value is actually returned.

          J 1 Reply Last reply
          0
          • W Wendelius

            No problem! So everything works now? Just notice that FirstOrDefault may also return null which wuold cause an exception since cStatus is integer so depending on the situation you may want to use integer? and check if a value is actually returned.

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #5

            I didn't think of that, I'll add it now

            21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups