Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4247348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:05:44+00:00 2026-05-21T04:05:44+00:00

I have a variable that contains an integer which I then want to save

  • 0

I have a variable that contains an integer which I then want to save as the value for a column (of type integer in the sql database and int32 in the entity model), but when I try this I receive the error:

“Conversion from string “” to type ‘Double’ is not valid”

I’m very confused by this since I’m not using a string or a double? The trouble-making line is:

UpdateBed.First.occupant = GetID

And here is the full code snippet:

    Private Sub btnReserve_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReserve.Click
    Using dbContext As pbu_housingEntities = New pbu_housingEntities
        ' Check that the room is still available.
        Dim hall As String = CStr(Session("hall"))
        Dim room As String = CStr(Session("room"))
        Dim checkOccupants = From p In dbContext.Rooms _
                             Let building_id = p.Building1.id _
                             Where p.building_name = hall _
                             Where p.room1 = room _
                             Select p.current_occupancy, p.max_occupancy, p.id, building_id

        If checkOccupants.First.current_occupancy >= checkOccupants.First.max_occupancy Then
            ' If it isn't available, let the student know.
            lblResult.Text = "Sorry, this room is now fully occupied. Please choose another room."
        Else
            ' If it is available, add the student to the room.
            Dim Occupant As New Resident
            Dim gender As String = CStr(Session("gender"))
            Dim person_name As String = CStr(Session("person_name"))
            Dim class_level As String = CStr(Session("class_level"))
            Dim semester As String = CStr(Session("term"))
            Dim people_code_id As String = CStr(Session("people_code_id"))
            Dim first_name As String = CStr(Session("first_name"))
            Dim last_name As String = CStr(Session("last_name"))
            Dim building_id As String = checkOccupants.First.building_id
            Dim room_id As String = checkOccupants.First.id
            Occupant.building = building_id
            Occupant.room = room_id
            Occupant.gender = gender
            Occupant.person_name = person_name
            Occupant.class_level = class_level
            Occupant.semester = semester
            Occupant.people_code_id = people_code_id
            Occupant.create_date = Date.Now
            Occupant.first_name = first_name
            Occupant.last_name = last_name
            dbContext.Residents.AddObject(Occupant)

            ' Increment the number of occupants in the room.
            Dim UpdateOccupancy = (From p In dbContext.Rooms _
                   Where p.building_name = hall _
                   Where p.room1 = room _
                   Select p).First
            UpdateOccupancy.current_occupancy = UpdateOccupancy.current_occupancy + 1

            ' Add the student to a bed.
            Dim UpdateBed = From p In dbContext.Beds _
                            Where p.building = building_id _
                            Where p.room = room_id _
                            Where p.occupant = "" _
                            Select p

            ' Get the student's ID from the residency table.
            Dim GetID = (From p In dbContext.Residents _
                        Where p.people_code_id = people_code_id _
                        Order By p.id Descending _
                        Select p.id).FirstOrDefault

            UpdateBed.First.occupant = GetID
            dbContext.SaveChanges()
            lblResult.Text = "Success! You have successfully requested residency in this room!"
        End If
    End Using
End Sub
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:05:45+00:00Added an answer on May 21, 2026 at 4:05 am

    This line in your LINQ query …

    Where p.occupant = ""
    

    … and this assignment …

    UpdateBed.First.occupant = GetID
    

    don’t seem to fit well together (if GetID is an Int32). Shouldn’t it be perhaps Where p.occupant = 0 or something?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 'price' variable that contains some integer number from a MySQL database.
I have a table called users which currently contains column money of type integer
I have a serialized object MyObject that contains integer foo. I set a value
I have a Picture model that contains a variable for a view count (integer).
I have a variable that contains the following JSON string: { 0 : Jun
I have a variable that contains : Sometimes array of strings and sometimes array
I have a variable that contains the entire html for a page as a
I have a variable that contains an array from form data, seen below: $option1
If I have a variable that contains text information (say taken from a textarea),
I have a variable foo that contains a time, lets say 4pm today, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.