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 8515651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:12:26+00:00 2026-06-11T05:12:26+00:00

Hi I got an InvalidCastException saying that Specified cast is not valid.. I dont

  • 0

Hi I got an InvalidCastException saying that “Specified cast is not valid.”. I dont know where is the problem. Does my code has an error?

This is my code:

 Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\patientinfo.accdb"
    Conn.Open()

    '====retrieve values in database=============
    Dim statement As String = " SELECT patient_name,patient_age,date_confinement,type_sickness, type_fluid, bottle_used, drop_rate FROM tblPatientInfo WHERE 1 ORDER BY ID "
    RetrieveInfos(statement)

End Sub
Public Sub RetrieveInfos(ByRef statement As String)
    Dim cmd As OleDbCommand = New OleDbCommand
    With cmd
        .CommandText = statement
        .CommandType = CommandType.Text
        .Connection = Conn
        .ExecuteNonQuery()


        '--read records in access database----------------
        Dim reader As OleDbDataReader = cmd.ExecuteReader


        If reader.Read Then

            lblName.Text = reader.GetString(0)
            lblAge.Text = reader.GetString(1)
            lblDate.Text = reader.GetString(2)
            lblSickness.Text = reader.GetString(3)
            lblFluid.Text = reader.GetString(4)
            lblBottle.Text = reader.GetString(5)
            lbldrops.Text = reader.GetString(6)

            reader.Close()
        End If
    End With
End Sub

Any help would be appreciated. Thanks! :3

  • 1 1 Answer
  • 0 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-06-11T05:12:28+00:00Added an answer on June 11, 2026 at 5:12 am

    Based on your comment to the question, I would suggest changing

    lblAge.Text = reader.GetString(1)

    to

    lblAge.Text = reader.GetInt32(1).ToString

    Also, make sure you use the appropriate Get for each column. For a Date you should use GetDateTime(). Here is a link to the MSDN for OleDbDataReader; the left side will have a list of all the methods that you can use for reference.

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

Sidebar

Related Questions

I've got a painfully simple table that is giving me a Specified cast is
Guys, I've got this problem that I searched almost everywhere (maybe I don't know
got some problems. Built an applet that has to be used step-by-step. After each
Got a problem with my add function to my database. The following code hangs
I've got a Serializable class that has been in use in production since about
I have got a native join sub query problem in MySQL Entity. SQL code
I got the following error when running the test code. How to workaround the
Got the new Retina MacBook and it has not been playing nice with xCode.
got a bit of a problem with Zend not adding the base url into
Got this ScopeExit class off code-project but it would not build on GCC 4.5.3.

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.