Solved

SQL Datetime Variable

Posted on 2006-06-13
10
403 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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