Reputation: 1
I am stuck with little problem. I have a sql
database with DATE column. It is populated from a Label like this: Label1.text = Date.today
and need to show records from one date in datagridwiev. So I need filter date using date from Label. So far I have this:
Public Sub ShowData()
cmd = New SqlCommand("Select * FROM Cisnik WHERE Datum = #" & Label3.Text & "# ", con)
If con.State = ConnectionState.Closed Then con.Open()
myDA = New SqlDataAdapter(cmd)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "Cisnik")
DGV3.DataSource = myDataSet.Tables("Cisnik").DefaultView
End Sub
This code throws : Incorrect syntax near '11.'. The number 11 is a part of European form of date 24.12.2018
The database works OK. Only need this filter problem to solve.
Upvotes: 0
Views: 680
Reputation:
Try:
cmd = New SqlCommand("Select * FROM Cisnik WHERE Datum = '" & cdate(label3.Text).ToString("yyyy-MM-dd") & "'", con)
Your query will be:
Select * FROM Cisnik WHERE Datum = '2018-11-11'
(date example)
Upvotes: 1