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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:22:09+00:00 2026-06-07T20:22:09+00:00

nudAge.Value is numeric up down. In my sql database, it is Age(int, null) .

  • 0

nudAge.Value is numeric up down. In my sql database, it is Age(int, null).
I did,

      insert.Parameters.AddWithValue("@age", nudAge.Value.ToString())

I am not sure if I should use .ToString()

date_of_confinement is datetime in my db. Should the format be like this?

      insert.Parameters.AddWithValue("@date_of_confinement", dtpDate.Value.ToShortDateString)

Also, for number_of_bottles which is text in vb.net and Int in db, I’ve used Int32.Parse but not sure,

      insert.Parameters.AddWithValue("@number_of_bottles", Int32.Parse(txtBottle.Text))

but I still got the error ‘System.InvalidCastException’.

This is my code:

      PatientInfoConnection.Open() 'open database connection

      Dim sql As String = ""
      sql = "insert into PatientInfo (name, age, date_of_confinement,type_of_sickness, type_of_IVfluid, number_of_bottles, drop_rate)" & _
      " values (@name, @age, @date_of_confinement, @type_of_sickness, @type_of_IV_fluid, @number_of_bottles, @drop_rate)"


      Dim insert As New SqlCommand(sql, PatientInfoConnection)
      insert.Parameters.AddWithValue("@name", txtName.Text)
      insert.Parameters.AddWithValue("@age", Int32.Parse(txtAge.Text))
      insert.Parameters.AddWithValue("@date_of_confinement", Date.Parse(dtpDate.Value))
      insert.Parameters.AddWithValue("@type_of_sickness", txtSickness.Text)
      insert.Parameters.AddWithValue("@type_of_IV_fluid", txtFluid.Text)
      insert.Parameters.AddWithValue("@number_of_bottles", Int32.Parse(txtBottle.Text))
      insert.Parameters.AddWithValue("@drop_rate", Int32.Parse(txtDrop.Text))

      insert.ExecuteNonQuery()

This is my new code: ( I modified some. I didnt get any error but when i want to save by clicking save button, it didn’t do anything. Do I have problem with my connection to database? Thanks!)

      Private Sub PatientInfoBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PatientInfoBindingNavigatorSaveItem.Click
    Me.Validate()
    Me.PatientInfoBindingSource.EndEdit()
    Me.PatientInfoTableAdapter.Update(Me.PatientInfoDBDataSet.PatientInfo)

End Sub

Private Sub EditInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'PatientInfoDBDataSet.PatientInfo' table. You can move, or remove it, as needed.
    Me.PatientInfoTableAdapter.Fill(Me.PatientInfoDBDataSet.PatientInfo)

End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
    Try

        'To check if all values have been filled up
        If txtName.Text = "" Or txtAge.Text = "" Or dtpDate.Value = "" _
        Or txtSickness.Text = "" Or txtFluid.Text = "" Or txtBottle.Text = "" Or txtDrop.Text = "" _
        Then

            MsgBox("Please Complete All the Required Fields")

        Else
            Try

                Dim PatientInfoConnection As SqlConnection = New _
                SqlConnection("Server=CATH-PC; database=PatientInfoDB;user id=sa;password=********") 'connection to SQL database

                PatientInfoConnection.Open() 'open database connection

                Dim sql As String = ""
                sql = "insert into PatientInfo (name, age, date_of_confinement,type_of_sickness, type_of_IVfluid, number_of_bottles, drop_rate)" & _
                                   " values (@name, @age, @date_of_confinement, @type_of_sickness, @type_of_IV_fluid, @number_of_bottles, @drop_rate)"


                Dim insert As New SqlCommand(sql, PatientInfoConnection)
                insert.Parameters.AddWithValue("@name", txtName.Text)
                insert.Parameters.AddWithValue("@age", Convert.ToInt32(txtAge.Text))
                insert.Parameters.AddWithValue("@date_of_confinement", Date.Parse(dtpDate.Value))
                insert.Parameters.AddWithValue("@type_of_sickness", txtSickness.Text)
                insert.Parameters.AddWithValue("@type_of_IV_fluid", txtFluid.Text)
                insert.Parameters.AddWithValue("@number_of_bottles", Convert.ToInt32(txtBottle.Text))
                insert.Parameters.AddWithValue("@drop_rate", Convert.ToInt32(txtDrop.Text))

                insert.ExecuteNonQuery()

                PatientInfoConnection.Close() 'close database connection

                MsgBox("Successfully Saved")
                Me.Visible = False
                Mainform.Show()


            Catch myerror As MySqlException
                MessageBox.Show("Error Connecting to Database: " & myerror.Message & ". Please contact the operator")

            End Try
        End If
    Catch ex As Exception
    End Try
End Sub
  • 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-07T20:22:10+00:00Added an answer on June 7, 2026 at 8:22 pm

    Add break point on your method on step through each line to locate where is the exact line where your exception occurs.

    try this:

    Dim sql As String
    sql = "insert into PatientInfo (name, age, date_of_confinement,type_of_sickness, type_of_IVfluid, number_of_bottles, drop_rate)" & _
                          " values (@name, @age, @date_of_confinement, @type_of_sickness, @type_of_IV_fluid, @number_of_bottles, @drop_rate)"
    
    
                    Dim insert As New SqlCommand(sql, PatientInfoConnection)
                    insert.Parameters.AddWithValue("@name", txtName.Text)
                    insert.Parameters.AddWithValue("@age", Convert.ToInt32(txtAge.Text))
                    insert.Parameters.AddWithValue("@date_of_confinement", Date.Parse(dtpDate.Value))
                    insert.Parameters.AddWithValue("@type_of_sickness", txtSickness.Text)
                    insert.Parameters.AddWithValue("@type_of_IV_fluid", txtFluid.Text)
                    insert.Parameters.AddWithValue("@number_of_bottles", Convert.ToInt32(txtBottle.Text))
                    insert.Parameters.AddWithValue("@drop_rate", Convert.ToInt32(txtDrop.Text))
    
                    insert.ExecuteNonQuery()
    

    Regards

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

Sidebar

Related Questions

This is a homework. I'm not looking for answers, just a nudge into the
I already started learning online but everything out there seems oriented to developers not
Just as a disclaimer, I am not looking for any hard code solutions, but
I have a custom bar button item that I want to nudge down 5
I'm adding pg_search into a Rails app. I'm not completely understanding the configuration, and
Is there a way to make the parameters of this extension method 'intellisensible' from
I am trying to print a multiline message in R. For example, print(File not
I'm wondering if any seasoned C#/ SQL developers could give me a nudge in
I have a double value f and would like a way to nudge it
I am not well-versed in HTTP requests. How can I, using PHP, grab and

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.