473,618 Members | 3,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting date datatypes via ado.net

while inserting new records into SQL, i'm using the folloinwg
sqlstatement>

Dim MySQL as string = "Insert into roster (pname, pnotes, thedate)
values (@pname, @pnotes, @thedate)"

the sql parameter I'm using is >

cmd.Parameters. Add(New SQLParameter("@ thedate", thedate.text))

but i get an error : Syntax error converting datetime from character
string when trying to insert. the textbox syntax I'm using for the
textbox control is >

<asp:textbox id="thedate" runat="server"/>

not sure where to change the text coming from the textbox into a
"datetime" data type, as with old asp, you could use a poundsign
(something like "# thedate #") to make it a date object.

thanks for your help
JMuenchbourg

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #1
3 2445
use Convert.ToDateT ime(...)

cmd.Parameters. Add(New SQLParameter("@ thedate",
Convert.ToDateT ime(thedate.tex t)))

--
Hope this helps,
Zeeshan Mustafa, MCSD
"J. Muenchbourg" <an*******@dex. com> wrote in message
news:et******** ******@TK2MSFTN GP12.phx.gbl...
while inserting new records into SQL, i'm using the folloinwg
sqlstatement>

Dim MySQL as string = "Insert into roster (pname, pnotes, thedate)
values (@pname, @pnotes, @thedate)"

the sql parameter I'm using is >

cmd.Parameters. Add(New SQLParameter("@ thedate", thedate.text))

but i get an error : Syntax error converting datetime from character
string when trying to insert. the textbox syntax I'm using for the
textbox control is >

<asp:textbox id="thedate" runat="server"/>

not sure where to change the text coming from the textbox into a
"datetime" data type, as with old asp, you could use a poundsign
(something like "# thedate #") to make it a date object.

thanks for your help
JMuenchbourg

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



Jul 21 '05 #2


I get the same exact "Syntax error converting datetime from character
string" with >
cmd.Parameters. Add(New SQLParameter("@ thedate",
Convert.ToDateT ime(thedate.tex t)))

The date format I am using for 'thedate' is mm/dd/yyyy . Do I have to
explicitly use a format function to enter it as this?

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
AFAIK when inserting in a datetime column, when you put
'#1/1/2004#' -- returns: syntax error covnerting datetime from
character string.
'7/1/2004' (or any combination format) -- will work fine.

and the error you're having is coming from SQL Server.

Remember a date is a DATE, and it does not have any format.
When a date is represented in string, it has be in a format. A
format could be mm/dd/yyyy or any else format.

Check this:
http://msdn.microsoft.com/library/en...valuetopic.asp

<quote>
If the application specifies the database type, the bound value is converted
to that type when the provider sends the data to the server. The provider
attempts to convert any type of value if it supports the IConvertible
interface. Conversion errors may result if the specified type is not
compatible with the value.

Both the SqlDbType and DbType properties can be inferred by setting the
Value.
</quote>

So we know that date does not have a formatted and from
above quote we learn that SqlParameter() can/will convert frameworks
Date object to its equivalent type of Sql.

Before adding parameter confirm that thedate (TextBox) contains
a valid date (can be in any machien understandable format), by using
IsDate() method.

--
Hope this helps,
Zeeshan Mustafa, MCSD
"J. Muenchbourg" <an*******@dex. com> wrote in message
news:OJ******** ******@tk2msftn gp13.phx.gbl...


I get the same exact "Syntax error converting datetime from character
string" with >
cmd.Parameters. Add(New SQLParameter("@ thedate",
Convert.ToDateT ime(thedate.tex t)))

The date format I am using for 'thedate' is mm/dd/yyyy . Do I have to
explicitly use a format function to enter it as this?

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 21 '05 #4

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

Similar topics

13
9284
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted to the MYSQL date field. The type of field is INT (11) so that I can instead of the standard...
4
350
by: Robert Scarborough | last post by:
I have a Table in a Typed Dataset which contains a Date field called EventDate. I've ensured that the field is defined as Date as opposed to DateTime in the Typed Dataset. When I generate an xml file from an instance of this typed dataset using the ds.WriteXml method, all the dates come out formatted as follows: <EventDate>2004-01-26T00:00:00.0000000-05:00</EventDate>
1
5503
by: Keith Chadwick | last post by:
Been trying to use the ms:format-date() in one of my transformations. I have all of the necessary declarations in my xml as in <?xml version="1.0" ?> <data xml:space="default" xmlns:dt="urn:schemas-microsoft-com:datatypes"> myxml... </data>
15
18877
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract the value in timeonly format by using this command Format(now,"HH:mm:ss") But when I insert it into the Sql Server database, it embadded date value with it. the output looks like that "01/01/1900 08:59:00" in that case time is
3
335
by: J. Muenchbourg | last post by:
while inserting new records into SQL, i'm using the folloinwg sqlstatement> Dim MySQL as string = "Insert into roster (pname, pnotes, thedate) values (@pname, @pnotes, @thedate)" the sql parameter I'm using is > cmd.Parameters.Add(New SQLParameter("@thedate", thedate.text))
2
2478
by: John A Grandy | last post by:
VS05 : GridView control config'd to use SPs in SS05 One of the SPs takes a vchar(50) which in the T-SQL needs to be converted to a DateTime. How should I have the GridView format the text the user enters in the date col ? Currently, if user enters "2/14/2006" , I format it as '2/14/2006' ... but this gives me a runtime error:
6
3296
by: fniles | last post by:
I am using VB.NET 2003 and SQL Server 2000. I have a table with a datetime column type. When inserting into the table for that column, I set it to Date.Now.ToString("T") , which is something like "2:50:54 PM". But after the row is inserted and I check the data in the database, the column data is set to "1/7/2007 2:50:04 PM" (notice today's date in front of the time). If I insert data directly into the table in the Enterprise Manager, the...
10
16995
by: DontellTrevell via AccessMonster.com | last post by:
HELP!!....I need to calculate the numer of days elapsed between two field. But, the date format is YYYYMMDD. How can i accomplsh this? -- Dontell Trevell Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-access/200701/1
2
3072
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
0
8207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8593
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...
0
8453
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
7124
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...
1
6098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4064
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2582
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
1
1760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1455
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.