Hello Forum
Hello tout le monde
Gentelman ..svp
Comment faire pour afficher dans DataGridView2 les records qui ont atteint leur Date et leur Temps d'apres les Colonnes Date_IN et Hour_In
Une personne enregistree dans ma DataBase avec par exemple 10/05/2018 dans Date_In et avec 14:30 dans Hour_In s'affichera dans DataGridView2 des qu'il atteint cette Date et ce temps
Voici le code complet pour remplir DataGridView1 et pour enregistrer les records dans ma DataBase
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Imports System.Data.SqlClient
Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim StrCon As SqlConnection = Nothing
        Try
   StrCon = New SqlConnection("data source=MADA; initial catalog= DATAOBERGE;User ID=sa;Password=123456789;")
            Using DepCom As SqlCommand = New SqlCommand("Select * From TableOberge", StrCon)
                StrCon.Open()
                Using DepAdap As SqlDataAdapter = New SqlDataAdapter(DepCom)
                    Dim DepDT As DataTable = New DataTable
                    DepAdap.Fill(DepDT)
                    DataGridView1.DataSource = DepDT
 
                    Dim CurrentBs As BindingSource = New BindingSource()
                    CurrentBs.DataSource = DepDT
                    DataGridView2.DataSource = CurrentBs
                    CurrentBs.Filter = String.Format("[Date_IN] = #{0}# AND [Hour_IN] >= #{1}#", DateTime.Now.Date, DateTime.Now.Hour)
                End Using
                StrCon.Close()
            End Using
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            If StrCon IsNot Nothing Then
                If StrCon.State = ConnectionState.Open Then
                    StrCon.Close()
                End If
                StrCon.Dispose()
            End If
        End Try
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using Command As New SqlCommand With {.Connection = StrCon}
            With Command.Parameters
                Command.CommandText = "INSERT INTO [TABLEOBERGE] ([ID], [FIRSTNAME], [PHONE], [ADRESSE], [DATE_OUT], [HOUR_OUT], [DATE_IN], [HOUR_IN]) VALUES (@ID, @FIRSTNAME, @PHONE, @ADRESSE, @DATE_OUT, @HOUR_OUT, @DATE_IN, @HOUR_IN)"
                .AddWithValue("@ID", SqlDbType.Int).Value = TextBox1.Text
                .AddWithValue("@FIRSTNAME", SqlDbType.NVarChar).Value = TextBox2.Text
                .AddWithValue("@PHONE", SqlDbType.NVarChar).Value = TextBox3.Text
                .AddWithValue("@ADRESSE", SqlDbType.NVarChar).Value = TextBox4.Text
                .AddWithValue("@DATE_OUT", SqlDbType.Date).Value = TextBox5.Text
                .AddWithValue("@HOUR_OUT", SqlDbType.Time).Value = TextBox6.Text
                .AddWithValue("@DATE_IN", SqlDbType.Date).Value = TextBox7.Text
                .AddWithValue("@HOUR_IN", SqlDbType.Time).Value = TextBox8.Text
            End With
            If StrCon.State = ConnectionState.Closed Then StrCon.Open()
            If Command.ExecuteNonQuery() = 1 Then
                MsgBox("SUCCED ADD", MsgBoxStyle.MsgBoxRtlReading, "SUCCES")
            Else
                MsgBox("ERROR FATAL", MsgBoxStyle.MsgBoxRtlReading, "ERROR")
            End If
            StrCon.Close()
        End Using
    End Sub
End Class
Ici par exemple la date enregistree dans DataGridView1 c'est bien 05/11/2018 dans les deux record mais comme meme sont affiches audessous dans DatagridView2
Nom : p_859xqw0p1.jpg
Affichages : 87
Taille : 96,1 Ko
Nom : p_859j5ilv1.jpg
Affichages : 90
Taille : 70,3 Ko
Merci beaucoup d'avance pour l'aide
Cordialement
MADA