none
datetimepicker defaults value RRS feed

Answers

  • Hello,

    Here is a code sample

    To fully use this in regards to DatabaseServer and DefaultCatalog install my NuGet package.

    Imports System.Data.SqlClient
    Imports BaseConnectionLibrary.ConnectionClasses
    Public Class DataOperations
        Inherits SqlServerConnection
    
        Public Function GetSomeDate() As Date
            DatabaseServer = ".\SQLEXPRESS"
            DefaultCatalog = "ForumExample"
            Dim dateValue As Date = Nothing
    
            Dim sqlStatement As String = "SELECT SomeDate FROM dbo.Table_1"
    
            Using cn = New SqlConnection(ConnectionString)
                Using cmd = New SqlCommand() With {.Connection = cn, .CommandText = sqlStatement}
    
                    Try
                        cn.Open()
                        Dim reader = cmd.ExecuteReader()
                        reader.Read()
                        dateValue = reader.GetDateTime(0)
    
                    Catch ex As Exception
                        mHasException = True
                        mLastException = ex
                    End Try
                End Using
            End Using
    
            Return dateValue
    
        End Function
    End Class
    

    Form code

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ops As New DataOperations
        DateTimePicker1.Value = ops.GetSomeDate()
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by no[one] Monday, February 18, 2019 9:01 AM
    Wednesday, February 13, 2019 5:09 PM
    Moderator

All replies

  • Hi

    DateTimePicker1.Value = MyDate   (any valid Date)


    Regards Les, Livingston, Scotland

    Wednesday, February 13, 2019 3:56 PM
  • Hello,

    Here is a code sample

    To fully use this in regards to DatabaseServer and DefaultCatalog install my NuGet package.

    Imports System.Data.SqlClient
    Imports BaseConnectionLibrary.ConnectionClasses
    Public Class DataOperations
        Inherits SqlServerConnection
    
        Public Function GetSomeDate() As Date
            DatabaseServer = ".\SQLEXPRESS"
            DefaultCatalog = "ForumExample"
            Dim dateValue As Date = Nothing
    
            Dim sqlStatement As String = "SELECT SomeDate FROM dbo.Table_1"
    
            Using cn = New SqlConnection(ConnectionString)
                Using cmd = New SqlCommand() With {.Connection = cn, .CommandText = sqlStatement}
    
                    Try
                        cn.Open()
                        Dim reader = cmd.ExecuteReader()
                        reader.Read()
                        dateValue = reader.GetDateTime(0)
    
                    Catch ex As Exception
                        mHasException = True
                        mLastException = ex
                    End Try
                End Using
            End Using
    
            Return dateValue
    
        End Function
    End Class
    

    Form code

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ops As New DataOperations
        DateTimePicker1.Value = ops.GetSomeDate()
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by no[one] Monday, February 18, 2019 9:01 AM
    Wednesday, February 13, 2019 5:09 PM
    Moderator