473,769 Members | 3,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems converting a string to SQLDateTime

I've got a classic ASP application that I'm migrating
to .NET. In the client script we used to use the
following code to help build up the sql string. It
converted a text date to the SQL Server Date format.

sSQL = sSQL + SQLServerDate(R equest.Form
("PLANNEDEXITDA TE")) + ","

I'm now trying to do this server side in VB.NET but I
can't seem to find a way to do it using convert or
CType. They all complain they cannot convert strings to
sqldatetime format. Also there seems to be no conversion
to a plain SQLServerDate.

mydate = CType(Convert.T oDateTime(PLANN EDEXITDATE),
SqlTypes.SqlDat eTime)

I'm sure this is really simple but it's eluding me at
present. Does any one have an idea?

Thanks

Damon
Nov 18 '05 #1
2 2626
You should just be able to do:

Dim myDate As SqlDateTime =
Convert.ToDateT ime(Request.For m("PLANNEDEXITD ATE"))

What's the error you get when using your original code?

Regards,

Mun

--
Munsifali Rashid
http://www.munsplace.com/

"damon.f" <da*****@nospam .com> wrote in message
news:03******** *************** *****@phx.gbl.. .
I've got a classic ASP application that I'm migrating
to .NET. In the client script we used to use the
following code to help build up the sql string. It
converted a text date to the SQL Server Date format.

sSQL = sSQL + SQLServerDate(R equest.Form
("PLANNEDEXITDA TE")) + ","

I'm now trying to do this server side in VB.NET but I
can't seem to find a way to do it using convert or
CType. They all complain they cannot convert strings to
sqldatetime format. Also there seems to be no conversion
to a plain SQLServerDate.

mydate = CType(Convert.T oDateTime(PLANN EDEXITDATE),
SqlTypes.SqlDat eTime)

I'm sure this is really simple but it's eluding me at
present. Does any one have an idea?

Thanks

Damon

Nov 18 '05 #2
I've tried to use that converstion but it didn't work.

Interestingly I've just used DateTime.Parse( ) and that is
excepted!

My final line is:

sqlCmd.Paramete rs.Add(New SqlClient.SqlPa rameter
("@a_dtPlannedE xitDate",
System.Data.Sql DbType.DateTime )).Value = DateTime.Parse
(PLANNEDEXITDAT E)

Thanks for your effort

Damon
-----Original Message-----
You should just be able to do:

Dim myDate As SqlDateTime =
Convert.ToDate Time(Request.Fo rm("PLANNEDEXIT DATE"))

What's the error you get when using your original code?

Regards,

Mun

--
Munsifali Rashid
http://www.munsplace.com/

"damon.f" <da*****@nospam .com> wrote in message
news:03******* *************** ******@phx.gbl. ..
I've got a classic ASP application that I'm migrating
to .NET. In the client script we used to use the
following code to help build up the sql string. It
converted a text date to the SQL Server Date format.

sSQL = sSQL + SQLServerDate(R equest.Form
("PLANNEDEXITDA TE")) + ","

I'm now trying to do this server side in VB.NET but I
can't seem to find a way to do it using convert or
CType. They all complain they cannot convert strings to sqldatetime format. Also there seems to be no conversion to a plain SQLServerDate.

mydate = CType(Convert.T oDateTime(PLANN EDEXITDATE),
SqlTypes.SqlDat eTime)

I'm sure this is really simple but it's eluding me at
present. Does any one have an idea?

Thanks

Damon

.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7976
by: FrodoBaggins | last post by:
Dear Team, Attempting to insert a record into a SQL database, using the command: command.ExcuteNonQuery(); Get the following error message in the event log: SQLDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
4
2023
by: B. Fletcher | last post by:
Hi, I'm having some trouble with javascript code of mine: When the script runs, I vget an error in line 119: Number Expected. I'm not sure as to why this is happening. Any advice would be helpful. The source code is at the bottom of the post. Thankyou very much,
1
304
by: mhf | last post by:
I have a SqlDateTime object, but when I use DataBinder.Eval on it, the formatting is ignored: DataBinder.Eval(Container.DataItem, "mySqlDateTimeObj", "{0:d}") produces output like this: "10/17/2003 12:00:00 am" Why can't I use format specifiers on SqlDateTime objects??
1
1378
by: poppy | last post by:
I set up my parameters in code as follows : lTTState.startDate = Today.AddDays(-10) lTTState.startDate = Today lSqlCmd.Parameters.Add(New SqlParameter("@startDate", SqlDbType.DateTime)) lSqlCmd.Parameters("@startDate").Value = lTTState.startDate lSqlCmd.Parameters.Add(New SqlParameter("@endDate", SqlDbType.DateTime)) lSqlCmd.Parameters("@endDate").Value = lTTState.endDate
1
2054
by: Paperback Writer | last post by:
I need to insert null in a DateTime field and in the ASP.Net i got this error: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. How to accomplish that ? -- Please, check my theSpoke: http://www.thespoke.net/MyBlog/dgroh/MyBlog.aspx
5
1624
by: | last post by:
Can someone help me on a format problem. I am trying to do this.. format a string to a number. The string has a number with a colon in the middle. Format("1:30","00:00") returns 00:00 instead of 01:30 How can this be done? Thanks
5
35230
by: mlafarlett | last post by:
Alright..I've found lots of info on this error and most say assign System.DBNull.Value, System.Convert.DBNull, or System.Data.SqlTypes.SqlDateTime.Null to my stored proc param and the problem will be solved...NOT. I suspect all of these are the same thing, however, none solve my problem. What I have is vb.net code trying to put a null in a sql2000 datatime field. To further confuse things, it works on my PC and not from another. I...
3
2134
by: Mike9900 | last post by:
Hello, I am getting SqlDateTime overflow if I use .NET remoting on Windows XP and Windows XP is the server where the SQL server is located at. If my computer is Windows 2003 where the sql server is running and I use client as the windows XP I do not get this error. -- Mike
0
1024
by: Scott McNair | last post by:
My apologies for crossposting this; I originally posted it to m.p.d.l.vb.data, but then I noticed that the group is not very active so I decided to post here as well. Subject: Problems creating a TVF From: Scott McNair <smcnair@beachexpress.takethispartout.com> Newsgroups: microsoft.public.dotnet.languages.vb.data Hi,
0
9416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9849
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8861
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.