Re: Getting entries from an SQL database with datetime parameter

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Nick,

If you want to pass date to the function you have to verify if the parsed
format is what you want. You can use profiler to see exact form of the date
that is passed to database. On the other hand, you could use T-SQL CONVERT
funtion to convert date string into date time accordig to your needs. By the
way if there is a chance that someone will change default date format in
your database, you will run into troubles comparing date to string.

Peter

"Nick" <nick@xxxxxxxxxxxx> wrote in message
news:%23q8ZJNIXFHA.1148@xxxxxxxxxxxxxxxxxxxxxxx
>I have created a simple aspx page with a datagrid, a textbox and a button
>on it.
> I want the user to enter a date in the textbox press the button and return
> a list of items to the datagrid from an SQL database but I am having
> problems with the date selection.
>
> The field in the database is datetime format (dd-MM-yyyy hh:mm:ss)
> I expect the user to type in a specific date e.g. 10-05-2005 or
> 10/05/2005 and click the button.
>
> I have tested all the elements of the page and they all work. e.g. I've
> hard coded a query to populate the datagrid, tested that the button raises
> the event etc.
>
> But when I attempt to pass the date to the query via a parameter I either
> get an error or no data (even though I know it exists).
>
>
> The DateFrom variable is a String passed to the function. It is the value
> typed in to the textbox
>
> I've tried passing the value straight to the parameter as a string.
>
> dbParam_datefrom.ParameterName = "@datefrom"
> dbParam_datefrom.Value = DateFrom
> dbParam_datefrom.DbType = DbType.stringfixedlength
> dbCommand.Parameters.Add(dbParam_datefrom)
>
>
> And I've tried converting DateFrom to a DateTime object
>
> dbParam_datefrom.ParameterName = "@datefrom"
> dbParam_datefrom.Value = Convert.ToDateTime(DateFrom)
> dbParam_datefrom.DbType = DbType.DateTime
> dbCommand.Parameters.Add(dbParam_datefrom)
>
>
>
> My SQL query contains the code
>
> Dated>=@datefrom
>
> Dated is the database field with datetime format that I have in the WHERE
> clause
>
> Am I making a glaring novice mistake as I'm very new to .NET.
>
> Any help would be greatly appreciated as I'm really stuck.
>
> Thanks
> Nick
>


.



Relevant Pages

  • RE: Payroll Query
    ... I have tested both functions and the query against some dummy data, ... Yes the text column is in the format hh:mm and no there are no null values, ... function to return it as a Date/Time data type provided that that no value ... Public Function TimeSumAs String ...
    (microsoft.public.access.queries)
  • Re: [PHP] Date/time format?
    ... Jason Pruim wrote: ... I am trying to figure out what format a string is in in a database. ... Below is an example of one of the lines in the database, What I'm really interested in is how it represents the "day". ... I have not been able to find ANY info about that format, other then other people using it in blogs. ...
    (php.general)
  • Re: year to date conversion
    ... the date in ISO-format, i.e. exactly in the format the OP requested. ... It is rare to need to be database independent. ... Sure, but again, there are moments, where a PreparedStatement ... The string is created by java.sql.Date, ...
    (comp.lang.java.programmer)
  • ADO exception with character combination inside string...
    ... We also have various Delphi7 programs that operate on this database. ... These programs are set up to trap the exception in an ADO operation ... and log the query text that was in use when the exception happened. ... What happens is that if we have a string to store inside the database ...
    (borland.public.delphi.database.ado)
  • Re: Runtime Error 3079
    ... You are restricting the query on the TotalLogEnv column, ... effect turns it into an INNER JOIN, so you should simply use an INNER JOIN. ... format or an internationally unambiguous format they'll be interpreted ... Dim strWhere As String ...
    (microsoft.public.access.queries)