简体   繁体   English

VB.net中来自标签的SQL过滤器日期

[英]SQL filter Date from Label in VB.net

I am stuck with little problem. 我陷入了小问题。 I have a sql database with DATE column. 我有一个带有DATE列的sql数据库。 It is populated from a Label like this: Label1.text = Date.today and need to show records from one date in datagridwiev . 它是通过这样的Label填充的: Label1.text = Date.today ,需要显示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 这段代码抛出: Incorrect syntax near '11.'. The number 11 is a part of European form of date 24.12.2018 Incorrect syntax near '11.'. The number 11 is a part of European form of date 24.12.2018 The database works OK. Incorrect syntax near '11.'. The number 11 is a part of European form of date 24.12.2018数据库运行正常。 Only need this filter problem to solve. 只需要这个过滤问题即可解决。

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) (日期示例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM