Solved

SQL Datetime Variable

Posted on 2006-06-13
10
407 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
Industry Leaders: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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