i have three dropdownlist one is showing day, the other is showing month and the other is showing year they are as follows...
i have this procedure that is saving to a table in my sql server database
it is giving me an error which states
Cast from string "30/4/5" to type 'Date' is not valid.
Exception Details: System.InvalidCastException: Cast from string "30/4/5" to type 'Date' is not valid.
can someone please help me would really appreciate it
thanks in advance
Visual Basic:
Private Sub ddlDay_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDay.Load
Dim i As Integer
For i = 1 To 31
ddlDay.Items.Add(i)
Next
ddlDay.SelectedIndex = Date.Now.Day - 1
End Sub
Private Sub ddlMonth_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMonth.Load
Dim i As Integer
For i = 1 To 12
ddlMonth.Items.Add(MonthName(i).ToString)
Next
ddlMonth.SelectedIndex = Date.Now.Month - 1
End Sub
Private Sub ddlYear_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlYear.Load
Dim i As Integer
For i = Date.Now.Year - 5 To Date.Now.Year + 5
ddlYear.Items.Add(i)
Next
ddlYear.SelectedIndex = Date.Now.Year - (Date.Now.Year - 5)
End Sub
i have this procedure that is saving to a table in my sql server database
Visual Basic:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mydate As DateTime
mydate = CDate((ddlDay.SelectedIndex + 1).ToString + "/" + (ddlMonth.SelectedIndex() + 1).ToString + "/" + (ddlYear.SelectedIndex()).ToString)
Dim SqlSPParam2 As String = "@news_TitleEN"
Dim SqlSPParam3 As String = "@news_TextEN"
Dim SqlSPParam8 As String = "@news_dt"
Dim SqlParams As SqlParameter() = {New SqlParameter(SqlSPParam3, TextBox3.Text), New SqlParameter(SqlSPParam3, TextBox2.Text), New SqlParameter(SqlSPParam8, mydate)}
WfSqlDataPump.ExecuteNonQuery(connectionString, "sp_addnews", SqlParams)
Response.Redirect("newsadmin.aspx")
End Sub
it is giving me an error which states
Cast from string "30/4/5" to type 'Date' is not valid.
Exception Details: System.InvalidCastException: Cast from string "30/4/5" to type 'Date' is not valid.
can someone please help me would really appreciate it
thanks in advance