SQL+VB+ASPX Web Pick datat from sql db as per date selected in textbox

Baiju EP 141 Reputation points
2022-12-03T06:45:07.997+00:00

Hi I have a SQL+VB+ASPX Web in which I want to select data as per date . But when i change date field to date then its working if its datetime then its not working. My code is appended below.

Str = "Select Opening from Production1 where Products='" + prodtxt.Text + "' AND Date='" + dttxt.Text + "' "

i actually water to select data from table Production1 where producttxt.text and datetxt.text (selected date) -1 (previous date data)

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,551 Reputation points Microsoft Vendor
    2022-12-05T03:32:13.147+00:00

    Hi @Baiju EP ,
    The reason for not working should be that the date format is not correct.
    DateTime Struct:Represents an instant in time, typically expressed as a date and time of day.
    https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=net-7.0
    You can use Convert.ToDateTime to convert a specified value to a DateTime value.
    https://learn.microsoft.com/en-us/dotnet/api/system.convert.todatetime?view=net-7.0
    DateTime data1 = Convert.ToDateTime(dttxt.Text);

    datetxt.text (selected date) -1 (previous date data)

    Are you trying to get the previous day of the date? You can use the following code:

     DateTime data1 = Convert.ToDateTime(dttxt.Text).AddDays(-1);  
    

    You can check the value of dttxt.Text at a breakpoint.
    266947-image.png
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful