0

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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by TomW
0

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.

0

'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

Edited by TomW: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.