com >> problem with date parameter to SQL

by Crevit » Fri, 02 Dec 2005 22:33:22 GMT

Hi,

I want call a SQL stored procedure that have a input DateTime type
parameter.

From VB if I use string or date type variable, SQL generate ERROR on
incorrect data conversion.

What data type I must to use?

Thanks in advance
Crevit






com >> problem with date parameter to SQL

by MikeD » Fri, 02 Dec 2005 22:54:38 GMT







Post your VB code as well as the stored proc header. IMO, the best way to
avoid such problems is to use an ADO Command object and an Parameter objects
of the correct type.

--
Mike
Microsoft MVP Visual Basic






com >> problem with date parameter to SQL

by Bones Brigadier » Fri, 02 Dec 2005 23:17:41 GMT

I would say check the SQL Server's machine Locale Inputs. Maybe it is
expecting the Date to be in a different format.
Trace it and see how it's being sent...







problem with date parameter to SQL

by Crevit » Sat, 03 Dec 2005 18:43:00 GMT

Hi,

I have resolved!

Thanks

"MikeD" < XXXX@XXXXX.COM > ha scritto nel messaggio



objects




problem with date parameter to SQL

by Tony Proctor » Sat, 03 Dec 2005 20:09:29 GMT

I guess we'll never know now since the OP didn't post any code, or say what
the solution was

However, a useful tip when dealing with SQL dates across different locales
is to format them using the ISO 8601 international format, i.e.'yyyy-mm-dd
hh:mm:ss'

Tony Proctor









problem with date parameter to SQL

by Crevit » Tue, 06 Dec 2005 01:44:24 GMT

Sorry,

I have resolved with a correct use of ADO parameter object

crevit

"Tony Proctor" < XXXX@XXXXX.COM > ha scritto nel

what








Similar Threads

1. displaying previous date ranges based on user input date (date parameter)

Novice Crystal 9.0 user here. I'm creating a Project/task report by
consultant with subtotals and totals where the user enters a customer
and date range that was setup using Crystal date parameters and I need
to use the date range entered to calculate and display the previous
week(s), up to at least 3 previous weeks on the same report as well. 
How can I get the previous weeks on the report?

bls

2. Problem with Date type parameter - VB Crystal Report

3. Parameter.Type is adVarchar for CHAR parameters of SQL Server Stored Procedure

Hi All,

I am using SQL Server 7 and Visual Basic 6. SQL Server supports
'Provider parameter information'. When I use de Type property of a
Stored Procedure parameter that is defined as CHAR, I would expect
adChar. However, the value is adVarchar. It seems as if 'they' didn't
bother to return the exact type of parameter.

Does anybody know a work-around to distinguish CHAR from VARCHAR
parameters?

Thanks in advance,

Roel Schreurs

--------------------------------------------------------------
Example:
--------------------------------------------------------------
--SQL Server 7
alter procedure dbo.sp_T_TestParameterTypes
	( @p_Char char(3)
	)
as

	select @p_Char
	
go

--------------------------------------------------------------
'Visual Basic 6
Sub Test

    Dim cmdTestSP As Command
    Dim par AS Parameter
    
    Set cmdTestSP = New Command

    With cmdTestSP
        .CommandType = adCmdStoredProc
        .CommandText = "TestParameterTypes"
        .ActiveConnection = <connection>
        .Parameters.ReFresh
        For Each par In .Parameters
            Debug.Print "Name:", par.Name, " Type:", par.Type
        Next par
    End With

End Sub
--------------------------------------------------------------

4. Problem with function Date() in SQL in VB

5. Problem importing Date Field into SQL DB.

I'm trying to import from a text file into a Sql DB, but I'm getting hung up
on a date field.

My text file has the date in the dd/mm/yyyy format.
I Cast that field to CDate in VB.NET, which sets it to #12/31/2005#

On my Insert, I get a SQL error from the .NET SqlClient Data provider:
"Syntax Error converting datetime from character string"

I tried not casting it as Date, which passed it into the parameter as
"2005-12-31" but that gave me the same error.

Does anyone have any ideas?


6. SQL 2000 Date Problem - VB.Net

7. SQL query and system DATE problem

Hi to all.
I have a small problem I hope someone can help me with.
I am running a sql query to a csv file. The query searches for the
total of a column between 2 dates.

This is a copy of one of the query's:

Dim SF_SMT As New OleDb.OleDbCommand("Select count(*) from
fault_records.csv where F4 = '" & lblprod.Text & " ' " & " AND  F8  AND
F1 between #" & SelectproductForm.datestart & "# and #" & Now.Date &
"#", conn)



F1 contains the date.F4 is the "product" and F8 the fault code that I'm
totaling.
The query works fine(returns the correct value) if my computer regional
DATE setting is m/d/yyyy. If I change it to d/m/yyyy then the query
returns nothing. It runs , but does not return anything.
Why is this and how can I get around it.

If this software is only running on one machine it would not be to much
of a problem , but if I want to run it on various machines that may
have different DATE setting it won't work.

The software is written in vb.net
Any help would be appreciated.
Cheers
Rob

8. Excel VBA - SQL to .dbf date problem - GETTING DESPERATE