Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error on database

Status
Not open for further replies.

hendrikbez

Technical User
Nov 3, 2003
54
ZA
I have these code and are trying to make a windows form
-----------------------------------------------------
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 dateStr As String = lstMonth.SelectedItem.ToString() & "/" & lstDay.SelectedItem.ToString() & "/" & lstYear.SelectedItem.ToString()
'Dim dateStr As String = lstMonth.SelectedText & "/" & lstDay.SelectedText & "/" & lstYear.SelectedText

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()
End Sub
------------------------------------------------------
I want to write to Access Databse ,but get his error on

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

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

Additional information: Cast from string "//" to type 'Date' is not valid.
----------------------------------------------------
 
The error tells you exactly what is wrong - dateStr = "//" and therefore can't be converted to a date.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top