473,491 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Create 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 2434
use Convert.ToDateTime(...)

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

--
Hope this helps,
Zeeshan Mustafa, MCSD
"J. Muenchbourg" <an*******@dex.com> wrote in message
news:et**************@TK2MSFTNGP12.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.ToDateTime(thedate.text)))

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**************@tk2msftngp13.phx.gbl...


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

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
9265
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...
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...
1
5493
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"...
15
18860
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...
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...
2
2476
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...
6
3289
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...
10
16947
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...
2
3055
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...
0
7118
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,...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6862
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...
0
7364
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...
1
4886
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...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
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 ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.