Error in insert to table

I have the following code:

Private Sub btnvoegby_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvoegby.Click
        Dim dateStr As String = lstMonth.SelectedValue & "/" & lstDay.SelectedValue & "/" & lstYear.SelectedValue
        Dim dateStr1 As String = lstMonth1.SelectedValue & "/" & lstDay1.SelectedValue & "/" & lstYear1.SelectedValue

        rs.Open("Select * from ss", cnConnection, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
        rs.AddNew()
        rs.Fields("Naam").Value = txtNaam.Text
        rs.Fields("Van").Value = txtVan.Text
        rs.Fields("Geboorte_datum").Value = dateStr
        rs.Fields("Ouderdom").Value = txtouderdom
        rs.Fields("Sosiale_Profiel").Value = lstProfiel.SelectedValue
        rs.Fields("Aangesluit").Value = dateStr1
        rs.Fields("Onderwyser").Value = lstonnie
        rs.Fields("Add1").Value = txtadd1
        rs.Fields("Add2").Value = txtadd2
        rs.Fields("Add3").Value = txtadd3
        rs.Fields("Add4").Value = txtadd4
        rs.Fields("Tel_H").Value = txttelh
        rs.Update()

I am trying to insert to a table caled ss.mdb it then give me a error:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in adodb.dll

Additional information: Type mismatch.

it shows on this line 
      rs.Fields("Geboorte_datum").Value = dateStr
    
What must I change to let it work.

Where on the internet can I get more info/samples 
of how bv.net and ms Access works


Answer this question

Error in insert to table

  • gharryh

    Rkimble

    I have try it again and I have full in all the fields that is on the form, all the comboboxes were aslo have been given a value but it still gives me the same error

    Thanks

  • JoelAraujo

    Thanks for the replay, but now I am getting this error 

    An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

    Additional information: Cast from string "//" to type 'Date' is not valid.


    I am using comboboes for day,month and year as dropdown


    Private Sub btnvoegby_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvoegby.Click 
    Dim dateStr As String = lstMonth.SelectedValue & "/" & lstDay.SelectedValue & "/" & lstYear.SelectedValue 
    Dim dateStr1 As String = lstMonth1.SelectedValue & "/" & lstDay1.SelectedValue & "/" & lstYear1.SelectedValue 

    rs.Open("Select * from ss", cnConnection, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic) 
    rs.AddNew() 
    rs.Fields("Naam").Value = txtNaam.Text 
    rs.Fields("Van").Value = txtVan.Text 
    rs.Fields("Geboorte_datum").Value = dateStr 
    rs.Fields("Ouderdom").Value = txtouderdom 
    rs.Fields("Sosiale_Profiel").Value = lstProfiel.SelectedValue 
    rs.Fields("Aangesluit").Value = dateStr1 
    rs.Fields("Onderwyser").Value = lstonnie 
    rs.Fields("Add1").Value = txtadd1 
    rs.Fields("Add2").Value = txtadd2 
    rs.Fields("Add3").Value = txtadd3 
    rs.Fields("Add4").Value = txtadd4 
    rs.Fields("Tel_H").Value = txttelh 
    rs.Update() 

  • khaley

    If you're trying to set a value of "//" it means that when the string was built, the selected values on each combobox were blank.

    You'll want to check that the comboboxes all have values selected before you try to build a date from them.

  • Erich H. Franke

    The field "Geboorte_datum" is most likely a Date type field in the database.  Try wrapping a CDate() around your value.

    rs.Fields("Geboorte_datum").Value = CDate(dateStr)

  • R Hearn

    How did you fill your ComboBoxes

    If there's no ValueMember set then the SelectedValue will be blank.  Try SelectedText or SelectedItem.ToString() instead of SelectedValue.

  • Subrajit

    Thanks for the info Rkimble, but now I am getting this error or the same field "Geboorte_Datum".  This field is a date field (birtday) it has dropdown comboboxes
    for  day,month and Year

    An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

    Additional information: Cast from string "//" to type 'Date' is not valid.

     Dim dateStr As String = lstMonth.SelectedValue & "/" & lstDay.SelectedValue & "/" & lstYear.SelectedValue
            Dim dateStr1 As String = lstMonth1.SelectedValue & "/" & lstDay1.SelectedValue & "/" & lstYear1.SelectedValue

            rs.Open("Select * from ss", cnConnection, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
            rs.AddNew()
            rs.Fields("Naam").Value = txtNaam.Text
            rs.Fields("Van").Value = txtVan.Text


                                            rs.Fields("Geboorte_Datum").Value = CDate(dateStr)



            rs.Fields("Ouderdom").Value = txtouderdom
            rs.Fields("Sosiale_Profiel").Value = lstProfiel.SelectedValue
            rs.Fields("Aangesluit").Value = CDate(dateStr1)
            rs.Fields("Onderwyser").Value = lstonnie
            rs.Fields("Add1").Value = txtadd1
            rs.Fields("Add2").Value = txtadd2
            rs.Fields("Add3").Value = txtadd3
            rs.Fields("Add4").Value = txtadd4
            rs.Fields("Tel_H").Value = txttelh
            rs.Fields("Tel_K").Value = txttelk
            rs.Fields("Tel_M").Value = txttelm
            rs.Fields("Tel_V").Value = txttelv
            rs.Update()



  • Error in insert to table