Solved

SQL Datetime Variable

Posted on 2006-06-13
10
394 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now