0

Conversion from string "Widow/Widower" to type 'Integer' is not valid.

here is my code

classLibrary.addParameter("@Sex", SqlDbType.VarChar, txtSex.TextLength, txtSex.Text)
        classLibrary.addParameter("@Room_ID", SqlDbType.VarChar, txtRoom_ID.TextLength, txtRoom_ID.Text)
        classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cboxCStatus.SelectedItem, cboxCStatus.Text)
        classLibrary.addParameter("@Nationality", SqlDbType.VarChar, txtNationality.TextLength, txtNationality.Text)
        classLibrary.addParameter("@Religion", SqlDbType.VarChar, txtReligion.TextLength, txtReligion.Text)
3
Contributors
33
Replies
34
Views
6 Years
Discussion Span
Last Post by jlego
0

what does your addparameter function do. paste that
you cant make a string into an integer, doesnt work like that!

im guessing that when u pass the civil status, the function is expecting an integer and receiving a string. maybe change as integer to as string on ur function then use cint if you want to convert the string to an integer later down the road

0

hi tnx..

before i change cstatus as combobox, i used it as textbox. there was no error when i ran the application but when i experimented using combobox there arose problem saying invalidcastexception...

0

this is the code that was highlighted

classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cboxCStatus.SelectedItem, cboxCStatus.SelectedIndex)
0

here is my whole code

Private Sub btnAddPatient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddPatient.Click
        Dim strSQL As String = "addpatient"
        classLibrary = New ConnectionLibrary
        classLibrary.openConnection(strConnection)

        If Not classLibrary.isConnectionOpen() Then
            Exit Sub
        End If

        classLibrary.initializeCommand(strSQL)
        classLibrary.addParameter("@Patient_ID", SqlDbType.VarChar, txtPatient_ID.TextLength, txtPatient_ID.Text)
        classLibrary.addParameter("@patient_type", SqlDbType.VarChar, txtPatient_type.TextLength, txtPatient_type.Text)
        classLibrary.addParameter("@LName", SqlDbType.VarChar, txtLName.TextLength, txtLName.Text)
        classLibrary.addParameter("@FName", SqlDbType.VarChar, txtFname.TextLength, txtFname.Text)
        classLibrary.addParameter("@MName", SqlDbType.VarChar, txtMname.TextLength, txtMname.Text)
        classLibrary.addParameter("@Address", SqlDbType.VarChar, txtAddress.TextLength, txtAddress.Text)
        classLibrary.addParameter("@Birthplace", SqlDbType.VarChar, txtBirthplace.TextLength, txtBirthplace.Text)
        classLibrary.addParameter("@Birthdate", SqlDbType.VarChar, txtBirthdate.TextLength, txtBirthdate.Text)
        classLibrary.addParameter("@Age", SqlDbType.VarChar, txtage.TextLength, txtage.Text)
        classLibrary.addParameter("@Sex", SqlDbType.VarChar, txtSex.TextLength, txtSex.Text)
        classLibrary.addParameter("@Room_ID", SqlDbType.VarChar, txtRoom_ID.TextLength, txtRoom_ID.Text)
        classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cboxCStatus.SelectedItem, cboxCStatus.SelectedIndex)
        classLibrary.addParameter("@Nationality", SqlDbType.VarChar, txtNationality.TextLength, txtNationality.Text)
        classLibrary.addParameter("@Religion", SqlDbType.VarChar, txtReligion.TextLength, txtReligion.Text)
        classLibrary.addParameter("@Date_Admitted", SqlDbType.VarChar, txtDate_Admitted.TextLength, txtDate_Admitted.Text)
        classLibrary.addParameter("@Time_Admitted", SqlDbType.VarChar, Txttime_admitted.TextLength, Txttime_admitted.Text)
        classLibrary.addParameter("@Date_Discharged", SqlDbType.VarChar, txtdate_discharged.TextLength, txtdate_discharged.Text)
        classLibrary.addParameter("@Time_Discharged", SqlDbType.VarChar, txtTime_discharged.TextLength, txtTime_discharged.Text)
        classLibrary.addParameter("@Chart_ID", SqlDbType.VarChar, txtChart_ID.TextLength, txtChart_ID.Text)
        classLibrary.addParameter("@Occupation", SqlDbType.VarChar, txtOccupation.TextLength, txtOccupation.Text)




        objCommand.ExecuteNonQuery()
        refreshlist()
    End Sub
0
classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cboxCStatus.[B]selectedindex[/B], cboxCStatus.SelectedIndex)

try that, if it doesnt work ill load vb and see if i can find anything

0

when i tried it another error arises

sqlexception was unhandled
Cannot insert explicit value for identity column in table 'AdmissionRecord' when IDENTITY_INSERT is set to OFF.

0

i dunno, im guessing that is access or something? i only have experience programming with mysql..

if i had to guess, u need to configure it to allow writes (permission error or something maybe) ?

0

aww sorry looks like i got but selectedindex lists the number not the actual text or selected item

for example
i choose my status single
then the output on the listview is 1
when i choose status married
the output is 2

0

Oh you want the text from the combobox - sorry i thought you wanted the index.

it is just combobox.text for the text that is currently selected

0

... so you are saying the combo box will have two options.
male, female

male = 1
female = 2


the index for the male would be 0, and female would be 1 i beleive.
you could accomplish this with a class that adds a .tag to a combobox, you could set the tag as 1 or 2. other than that im not really sure how you can get that to work.

you could make an integer

dim intinteger as integer = 0

if me.cmbsex.text = "male" then
intinteger = 1
elseif me.cmbsex.text = "female" then
intinteger = 2
end if

im not really sure what u want to do sorry

0

hi thanks what i want to display is the text like when user choose male the output is male

0
classLibrary.addParameter("@Sex", SqlDbType.VarChar, txtSex.TextLength, txtSex.Text)
        classLibrary.addParameter("@Room_ID", SqlDbType.VarChar, txtRoom_ID.TextLength, txtRoom_ID.Text)
        classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cboxCStatus.SelectedItem, cboxCStatus.Text)
        classLibrary.addParameter("@Nationality", SqlDbType.VarChar, txtNationality.TextLength, txtNationality.Text)
        classLibrary.addParameter("@Religion", SqlDbType.VarChar, txtReligion.TextLength, txtReligion.Text)
0
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ComboBox1.Items.Add("male")
        Me.ComboBox1.Items.Add("female")
    End Sub

    Private Sub AddParameter(ByVal index As Integer, ByVal text As String)
        MsgBox("INDEX: " & index & " - SEX: " & text)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call AddParameter(ComboBox1.SelectedItem, ComboBox1.Text)
    End Sub
End Class

make a new project,
add a form
add a combobox
add a button
paste that code

hit play, and press the button.

i don't understand what exactly the problem is? is it because the item is returning 0 instead of 1 ?

Edited by jlego: n/a

0

i really dont know why the error message keeps saying that cboxcstatus is an integer type..

0

is it highlighting the cboxstatus.selecteditem or the cboxstatus.text?

what exactly does the error say?

0

invalidcast exception was unhandled


Conversion from string "" to type 'Integer' is not valid.
is it highlighting the cboxstatus.selecteditem or the cboxstatus.text? - both

0

classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cint(cboxCStatus.SelectedItem), cboxCStatus.Text.tostring)

what does the addparameter function look like

0

Just noticing that when you are adding the parameter:

classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cboxCStatus.SelectedItem, cboxCStatus.SelectedIndex)

That you are specifying a varchar type. Should that not be an Int?

As to your last error, it sounds like your Stored Procedure is attempting to add a record AND is specifying an ID.

I'm guessing that Patient_ID is the record id? Whatever it is, it's an Identity field which will automatically insert a value. You can't specify what the value will be:

classLibrary.addParameter("@Patient_ID", SqlDbType.VarChar, txtPatient_ID.TextLength, txtPatient_ID.Text)

0

codeword

i thought the same, however

classLibrary.addParameter("@Room_ID", SqlDbType.VarChar, txtRoom_ID.TextLength, txtRoom_ID.Text)

classLibrary.addParameter("@CivilStatus", SqlDbType.VarChar, cboxCStatus.SelectedItem, cboxCStatus.Text)

he said it doesnt error until civilstatus. and the @room_id insert is basically the same.. the txtroom_id.textlength is an integer, as is the cboxcstatus.selecteditem.

the room_id works however?

0

this is my code in listview

Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        Dim index As ListView.SelectedIndexCollection = ListView1.SelectedIndices
        Dim i As Integer = 0
        For Each i In index
            txtPatient_ID.Text = ListView1.Items(i).SubItems(0).Text
            txtPatient_type.Text = ListView1.Items(i).SubItems(1).Text
            txtLName.Text = ListView1.Items(i).SubItems(2).Text
            txtFname.Text = ListView1.Items(i).SubItems(3).Text
            txtMname.Text = ListView1.Items(i).SubItems(4).Text
            txtAddress.Text = ListView1.Items(i).SubItems(5).Text
            txtBirthplace.Text = ListView1.Items(i).SubItems(6).Text
            txtBirthdate.Text = ListView1.Items(i).SubItems(7).Text
            txtage.Text = ListView1.Items(i).SubItems(8).Text
            txtSex.Text = ListView1.Items(i).SubItems(9).Text
            txtRoom_ID.Text = ListView1.Items(i).SubItems(10).Text
            cboxCStatus.Text = ListView1.Items(i).SubItems(11).Text
            txtNationality.Text = ListView1.Items(i).SubItems(12).Text
            txtReligion.Text = ListView1.Items(i).SubItems(13).Text
            txtDate_Admitted.Text = ListView1.Items(i).SubItems(14).Text
            txtdate_discharged.Text = ListView1.Items(i).SubItems(15).Text
            Txttime_admitted.Text = ListView1.Items(i).SubItems(16).Text
            txtTime_discharged.Text = ListView1.Items(i).SubItems(17).Text
            txtChart_ID.Text = ListView1.Items(i).SubItems(18).Text
            txtOccupation.Text = ListView1.Items(i).SubItems(19).Text


        Next

    End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.