[Gambas-user] Search Between Dates

Benoît Minisini g4mba5 at gmail.com
Sun Oct 7 16:48:43 CEST 2018


Le 07/10/2018 à 01:19, Wael M via User a écrit :
> Hi all
> 
> I have a SQLite database
> I need to search between two dates
> I'm using this code but doesn't work
> it gives no error but returns nothing
> 
>   TextBox1.Text = Format(DateBox1.Value, "yyyy/m/d")
>    TextBox2.Text = Format(DateBox2.Value, "yyyy/m/d")
> 
>    $rs = ModMain.$con.Exec("SELECT * FROM Visits WHERE Vdate BETWEEN '" & TextBox1.Text & "' AND '" & TextBox2.Text & "'")
>    
> any suggestions?
> 
> WaeL
> 
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
> 

You have to use the value substitution feature!

In other words, you must not write:

$rs = ModMain.$con.Exec("SELECT * FROM Visits WHERE Vdate BETWEEN '" & 
TextBox1.Text & "' AND '" & TextBox2.Text & "'")

BUT:

$rs = ModMain.$con.Exec("SELECT * FROM Visits WHERE Vdate BETWEEN &1 AND 
&2", Val(TextBox1.Text), Val(TextBox2.Text))

And you must ensure that the text inside the TextBox controls is a date 
following the representation of your locale, so that Val() actually 
returns a date.

Regards,

-- 
Benoît Minisini


More information about the User mailing list