Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello!
I am using VB.net 2005 and MS SQL Server 2005

So I tried executing this code in sql:
SQL
SELECT     queueno, plateno, CONVERT(varchar(10), qdate, 101) AS DateToday
FROM         dbo.TRN_Queue
WHERE     (CONVERT(varchar(10), qdate, 101) = '05/14/2014')

and its giving me this table:
PHP
queueno     platenumber     DateToday
1G001         ABC123        05/14/2014
1G002         DEF456        05/14/2014

^This is the table i want to show in my Form1

I created a form in VB.net that contains Label1. Label1 is the date today.
This is my code for Lable1:
VB
Label1.Text = DateTime.Now.ToString("MM/dd/yyyy")

so it shows this: 05/14/2014

So tried using Label1 as filter for my DGV. and i used this code for DGV:
VB
"SELECT queueno, plateno, CONVERT(varchar(10), qdate, 101) AS DateToday FROM dbo.TRN_Queue WHERE (CONVERT(varchar(10), qdate, 101) = '" & Label1.Text & "')"


But when i run my project, the DGV is empty.
Help please!
Posted
Updated 13-May-14 17:01pm
v2

1 solution

If you need to get records of today, change the SQL as below. Note that I have removed taking date from label, SQL GETDATE function can be used to get the current date. we don't need to send it from UI.
SQL
SELECT queueno, plateno, CONVERT(varchar(10), qdate, 101) AS DateToday FROM dbo.TRN_Queue WHERE CAST(qdate AS DATE) = CAST(GETDATE() AS DATE)

Or you need to get records for given date, use SQL parameter
SQL
SELECT queueno, plateno, CONVERT(varchar(10), qdate, 101) AS DateToday FROM dbo.TRN_Queue WHERE CAST(qdate AS DATE) = CAST(@dateParam AS DATE)

then you need to set the value of parameter as below
VB
cmd.Parameters.Add("@dateParam", SqlDbTypes.DateTime).Value = DateTime.Now
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900