Solved

SQL Datetime Variable

Posted on 2006-06-13
10
411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

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.

Question has a verified solution.

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

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 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