Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai,
I am create a windows form. I stored expiry date in Sql server database name "test" and the table name "exp" have id(primary key) and date attributes. And my program is a button clicks then the usercontrole show. If date expired when show a message box "the app expired"


How can get the date from the the "Sqlserver database" to "Datetime dt2".

Database name = test
Table name= exp

What I have tried:

Button1_clicked

Datetime dt1= datetime.now;
Datetime dt2= expirydate from database

If(dt1>dt2)
{
Messagebox.show("App expired");
}
Else
{
Usercontrole.bringToFront();
}
Posted
Updated 12-Sep-18 21:23pm

1 solution

Try:
VB
Using con As SqlConnection = New SqlConnection(strConnect)
    con.Open()
    Using cmd As SqlCommand = New SqlCommand("SELECT myDateColumn FROM myTable WHERE rowID = @RI", con)
        cmd.Parameters.AddWithValue("@RI", valueWhichSelectsTheRightRow)
        Using reader As SqlDataReader = cmd.ExecuteReader()
            While reader.Read()
                Dim dt As DateTime = CType(reader("myDateColumn"), DateTime)
                Console.WriteLine(dt)
            End While
        End Using
    End Using
End Using
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900