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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:41:11+00:00 2026-06-08T03:41:11+00:00

I’m new in Visual Studio and as well as SQL Server. I got confused

  • 0

I’m new in Visual Studio and as well as SQL Server. I got confused on how to insert data from visual studio application

This is my code:

Try

'===============Add New Patient===================
        patient_name = txtName.Text
        patient_age = nudAge.Value
        date_of_confinement = dtpDate.Value
        type_of_sickness = txtSickness.Text
        type_of_IVfluid = txtFluid.Text
        number_of_bottles = txtBottle.Text
        drop_rate = nudDrop.Value

        'To check if all values have been filled up
        If txtName.Text = "" Or nudAge.Value = "" Or dtpDate.Value = "" _
        Or txtSickness.Text = "" Or txtFluid.Text = "" Or txtBottle.Text = "" Or nudDrop.Value = "" _
        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 model (name, age, date_of_confinement,type_of_sickness, type_of_IVfluid, number_of_bottles, drop_rate)" & _
                       " values (@txtName.Text, @nudAge.Value, @dtpDate.Value, @txtSickness.Text, @txtFluid.Text, @txtBottle.Text, @nudDrop.Value)"

                Dim insert As New SqlCommand(sql, PatientInfoConnection)

                insert.Parameters.AddWithValue(patient_name, @txtName.Text)'@ error  
                insert.Parameters.AddWithValue("val2", nudAge.Value) 'error
                insert.Parameters.AddWithValue(Name, patient_name) 'not sure

                insert.ExecuteNonQuery()

                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

I am not sure about the SqlCommand as I don’t know how to save the user’s input to my database. I want to add value entered in a textbox to my database

Dim insert As New SqlCommand(sql, PatientInfoConnection)

insert.Parameters.AddWithValue(patient_name, @txtName.Text) 'error @ char is not valid

insert.Parameters.AddWithValue("val2", nudAge.Value) 'error

insert.Parameters.AddWithValue(Name, patient_name) 'not error but not sure

name(text,null) is one of the columns of my database which I designed in SQL Server Management Studio

Please help me. Any help would be appreciated. Thanks!

I got changed insert.Parameters.AddWithValue("@name", txtName.Text) and the sql = “insert into model part as what suggested but I got an error

“A first chance exception of type ‘System.InvalidCastException’
occurred in Microsoft.VisualBasic.dll”

I am confused

  • 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-08T03:41:13+00:00Added an answer on June 8, 2026 at 3:41 am

    You are close.

    Try just a single variable name, and match them.

    So SQL would be:

    sql = "insert into model (name, age, date_of_confinement,type_of_sickness, type_of_IVfluid, number_of_bottles, drop_rate)" & _
                       " values (@name, @age, @dateOfConfinement, @sicknessType, @fluidType, @bottleAmount, @dropRate)"
    

    Then set parameter like:

    insert.Parameters.AddWithValue("@name", txtName.Text)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace

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.