In my database, using SQL Server 2014
, with a table named TableOberge
and with column named Date-In
of type Date
, and with a second column named Hour-In
of type Time(7)
.
With this query I want to display the records that have reached their dates and times in DatagridView1... but I have failed to display them correctly.
Any Help please:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dbb_Connection()
Using InfoAdapter As New SqlDataAdapter("SELECT * FROM TABLEOBERGE WHERE [DATE_IN] >= CONVERT(date, GETDATE()) AND [HOUR_IN] >= convert(time(0),getDate())", StrCon)
InfoTable = New DataTable
InfoAdapter.Fill(InfoTable)
DataGridView1.DataSource = InfoTable
End Using
End Sub
My code for add record :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dbb_Connection()
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
http://www.vbforums.com/showthread.php?862331-Display-record-with-condition-of-date-and-time And Here https://www.developpez.net/forums/d1851524/dotnet/langages/vb-net/afficher-records-conditions-date-time/