Ok heres my problem which i'm starting to find very annoying :S
I am trying to load a date stored on my sql server database into a date time picker.

Dim MyDate As Date = (DetailLookup("PLIExpiry", "tblConcessions", "ConcessionID", varCompanyKey))

                        frmConcessions.dtpPPLIExiryDate.Value = MyDate

DetailLookup is a public function that obtains data from the database.

Public Function DetailLookup(ByVal varColumnIn As String, ByVal varTableIn As String, ByVal varIDTypeIn As String, ByVal varCompanyIDIn As String)

        objCommand.Connection = objConnection

        Dim varCommand As String = "SELECT " & varColumnIn & " FROM " & varTableIn & " WHERE " & varIDTypeIn & "='" & varCompanyIDIn & "';"
        Dim da As SqlDataReader
        Dim Reading As String

        objCommand.CommandText = varCommand
        da = objCommand.ExecuteReader
        Reading = (da(varColumnIn))

        Return Reading

    End Function

The result of this is that there are no errors; instead the datetimepicker just displays todays date. I am completely bamboozled as to why this does not work! Can anybody help?

Many thanks

That is a really awfull way of trying to get your results. As to your answer though, your function is returning a string datatype of a date but you need to apply an actual datetime datatype to your datetimepicker.value.

'Create the stored procedure in your database
'it is cleaner and actually will run faster!

Create Procedure spGetConcessionDate

	@ConcessionId As VarChar(25)


Select PLIExpiry 
From tblConcessions 
Where ConcessionId = @ConcessionId
Public Function GetConcessionExpirationDate(ByVal strCompanyId As String) As Date

        Dim dtExp As Date = Nothing

        Using con As New SqlConnection()
            Dim cmd As New SqlCommand

            cmd.Connection = con
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "spGetConcessionDate"
            cmd.Parameters.AddWithValue("@ConcessionId", strCompanyId)

            dtExp = CDate(cmd.ExecuteScalar)

        End Using

        Return dtExp

    End Function

Edited 7 Years Ago by TomW: n/a

This article has been dead for over six months. Start a new discussion instead.