Search This Blog

Check Date (DatePicker) If Already Exists in Database

This tutorials is to identify if the Date in DatePicker is already exists in Database.


Follow this step...

Add ODBC in your Components


Select "Microsoft ADO Data Control 6.0 (OLEDB)"


Drag "Adodbc1" in to you VB Form


Open your Command Button and paste this code.


Public dbcon As New ADODB.Connection
Public rst As New ADODB.Recordset


Private Sub Command1_Click()

 Set dbcon = New ADODB.Connection
    dbcon.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myDBRecords"


 If rst.State = 1 Then rst.Close
   
      strsql = "select * from tblrecords where mydate='" & DTPicker1.Value & "'"
      rst.Open strsql, dbcon, adOpenKeyset, adLockOptimistic
        While Not rst.EOF
            If DTPicker1.Value = rst!mydate Then
                MsgBox "The Date Already Exists!", , "Success"
                Exit Sub
            Else
                MsgBox "The Date not Found!", , "Error"
            End If
           
            rst.MoveNext
        Wend
        rst.Close


End Sub








Now run your VB Project (click F5) on your keyboard
Done!!!.