473,320 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

error:the string was not recognized as a valid DateTime.

35
hi all, i'm trying to insert the time/date a button was clicked on a gridview and it generates an error:the string was not recognized as a valid DateTime.There is an unknown word starting at index 0 i have changed the culture to en-US but it still doesn't work. i actually created the date/time column after some data had been entered into the table so the column allows nulls. this is my code:

InsertCommand="INSERT INTO test101(Surname,Names,Registration,Date/Time)VALUES (@Surname, @Names, @Registration,@DateTime,getdate())"

<Insert Parameters><asp:Parameter DefaultValue= DateTime.Now() Type=DateTime Name="DateTime" /></Insert Parameters>

any suggestions?
Aug 28 '07 #1
10 4072
Plater
7,872 Expert 4TB
You shouldn't be using DateTime.Now() but instead be using DateTime.Now, as Now is not a function.

If it doesn't like that, try DateTime.Now.ToString()
Aug 28 '07 #2
kenobewan
4,871 Expert 4TB
Have you tried Now()? I seem to recall getDate returning the name of the day first, so depends on the design of your table.
Aug 28 '07 #3
mercea
35
You shouldn't be using DateTime.Now() but instead be using DateTime.Now, as Now is not a function.

If it doesn't like that, try DateTime.Now.ToString()
now the error says "conversion failed when converting DateTime from character to string"
Aug 28 '07 #4
Plater
7,872 Expert 4TB
How did you name a colum "Date/Time" what is it's data type?
Have you checked the msdn on what datatypes convert to what?
Aug 28 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
hi all, i'm trying to insert the time/date a button was clicked on a gridview and it generates an error:the string was not recognized as a valid DateTime.There is an unknown word starting at index 0 i have changed the culture to en-US but it still doesn't work. i actually created the date/time column after some data had been entered into the table so the column allows nulls. this is my code:

InsertCommand="INSERT INTO test101(Surname,Names,Registration,Date/Time)VALUES (@Surname, @Names, @Registration,@DateTime,getdate())"

<Insert Parameters><asp:Parameter DefaultValue= DateTime.Now() Type=DateTime Name="DateTime" /></Insert Parameters>

any suggestions?
the fields you want to be populated are surname, name, registration, date/time (4 fields)
and you are passing 5 values.... you should rather get an sql error
Aug 28 '07 #6
mzmishra
390 Expert 256MB
what is the statement @DateTime,getdate() in your sql.I guess this is creating the problem
Aug 29 '07 #7
mercea
35
hi guys, thanks for all your input. i tried all your suggestions but unfortunately non of them worked.any more?
Aug 29 '07 #8
Plater
7,872 Expert 4TB
If your column is really called "Date/Time" then:

InsertCommand="INSERT INTO test101(Surname,Names,Registration,Date/Time)VALUES (@Surname, @Names, @Registration,@DateTime)"

<Insert Parameters><asp:Parameter DefaultValue= DateTime.Now Type=DateTime Name="DateTime" /></Insert Parameters>
Aug 29 '07 #9
mercea
35
If your column is really called "Date/Time" then:

InsertCommand="INSERT INTO test101(Surname,Names,Registration,Date/Time)VALUES (@Surname, @Names, @Registration,@DateTime)"

<Insert Parameters><asp:Parameter DefaultValue= DateTime.Now Type=DateTime Name="DateTime" /></Insert Parameters>
i've tried that before and when i do that, the error is
:the string was not recognized as a valid DateTime.There is an unknown word starting at index 0
Aug 30 '07 #10
Plater
7,872 Expert 4TB
I dunno then. It works for me.
Aug 30 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jim | last post by:
Any idea what is causing this error? 006~ASP 0230~Server.Transfer Error~The call to Server.Transfer failed while loading the page. Just read about benefits of Server.Transfer over...
0
by: microsoft | last post by:
Hi People, when I try to modify an active directory user programatically, I receive the following exception: The server is unwilling to process the request Reading the microsoft web site, I...
0
by: yelena | last post by:
Hello, We need to use version php-4.4.0-Win32 because one of the portal software doesn't support version php-5.0.5-Win32. We cannot get the PHP setup part working. Here is the error message: ...
8
by: chippy | last post by:
Hi, I've a VB script that creates a Access object in a word doc. Here is the full script. It works for all but the Export. Which always fails with a 3011 error. If I do the same in Access as a...
1
by: Mr. x | last post by:
Hello, If I did : try ... do something catch ... do something end try ....
1
by: Adrian Turner | last post by:
I am just starting developing with .Net(Have used asp for years). I have created a very simple upload page which once uploaded opens the file(excel) and displays the data. If I Attempt to re-run...
1
by: Omatase | last post by:
Here is my code: CDO.Message iMessage = new CDO.MessageClass(); string sFrom; string sDate; iMessage.DataSource.Open(bstrURLItem,null, ADODB.ConnectModeEnum.adModeRead,...
1
by: Mad Scientist Jr | last post by:
For some reason I can't get a WebClient to access an outside URL from behind our firewall. The code works when it runs outside the firewall. I turned on windows authentication in the web.config...
1
by: agarwalsunitadhn | last post by:
Hi I want to declare a coonectionstring in winapps as declared in web.config file in webapps. I declare that in app.config as follows <connectionStrings> <add...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.