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

        objConnection.Open()
        objCommand.CommandText = varCommand
        da = objCommand.ExecuteReader
        da.Read()
        Reading = (da(varColumnIn))
        objConnection.Close()

        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
Atove

Recommended Answers

All 2 Replies

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)

As

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)

            con.Open()
            dtExp = CDate(cmd.ExecuteScalar)
            con.Close()

            cmd.Dispose()
            con.Dispose()
        End Using

        Return dtExp

    End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.