Solved

SQL Datetime Variable

Posted on 2006-06-13
10
404 Views
Last Modified: 2008-02-26
Hi Guys,

I am calling a store procedure from asp.net webpage and one of whose parameters are of type datetime and I write the following code to add the sql parameters:

        Dim st As String
        Dim dt as datetime
       
        st = DropDownList17.SelectedValue + "/" + DropDownList10.SelectedValue + "/" + DropDownList5.SelectedValue _
        + " " + DropDownList3.SelectedValue + ":" + DropDownList4.SelectedValue + ":00"

        dt = DateTime.Parse(st)

 Dim p3 As New SqlParameter("@dateto", SqlDbType.DateTime, dt)

And I get an error value of type DATE CANNOT BE CONVERTED TO INTEGER.

Any help much appreciated.

0
Comment
Question by:radhakrishan
  • 4
  • 4
  • 2
10 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 16894283
What is the stored procedure or SQL statement you are using?
0
 

Author Comment

by:radhakrishan
ID: 16894306
The store procedure is as follows:


CREATE procedure spcheckbookings
@categoryid as integer,
@equipmentid as integer,
@dateto as datetime,
@dateend as datetime
as

Select count(*) as Counter
from tbBookings
where
CategoryId = @CategoryId
and
EquipmentId = @EquipmentId
and
(
       (dateto >= @dateto    AND @dateto    <= dateend) -- requested period starts inside of an existing period
        OR (dateto >= @dateend AND @dateend <= dateend) -- requested period ends inside of an existing period
        OR (dateto <= @dateto    AND @dateend <= dateend) -- requested period falls completely inside an existing period
        OR (dateto >= @dateto    AND @dateend >= dateend) -- requested perod completely overlaps an existing periodf
)
0
 

Author Comment

by:radhakrishan
ID: 16894317
i also get an error saying "STRING CANNOT BE CONVERTED TO DATETIME" now.


0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16894355
3rd parameter of Dim p3 As New SqlParameter("@dateto", SqlDbType.DateTime, dt)
is size of the parameter type. But u gave it as value of the parameter.
try like this
 Dim p3 As New System.Data.SqlClient.SqlParameter("@dateto", SqlDbType.DateTime, 4)
        p3.Value = dt
--pradeep
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16894399
try like this
 Dim st As String
        Dim dt As New DateTime(2003, 7, 31, 10, 30, 0)
        Dim p3 As New System.Data.SqlClient.SqlParameter("@dateto", SqlDbType.DateTime, 4)
        p3.Value = dt

--pradeep
0
 
LVL 14

Expert Comment

by:existenz2
ID: 16894402
>> i also get an error saying "STRING CANNOT BE CONVERTED TO DATETIME" now.

Change it so it is according to mm-dd-yyyy hh:mm:ss
0
 

Author Comment

by:radhakrishan
ID: 16894497
Hi.


I m still struct on error of "STRING CANNOT BE CONVERTED TO DATETIME"

The value of String i m tryin to convert looks like:
st = 5-29-2006 12:00:00

I can't think whats wrong with the above value..

and then write
dt = Datetime.Parse(st)

Do I need to import any class to achieve this?

cheers
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16894568
pass the values to DateTime Constructor
 Dim dt As New DateTime(2003, 7, 31, 10, 30, 0)
0
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 200 total points
ID: 16894573
Dim st As String
        Dim dt As New DateTime(2003, 7, 31, 10, 30, 0)
        Dim p3 As New System.Data.SqlClient.SqlParameter("@dateto", SqlDbType.DateTime, 4)
        p3.Value = dt
0
 

Author Comment

by:radhakrishan
ID: 16894937
That's great Pradeep thanks very much.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question