Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 5th, 2009, 03:47 PM
Authorized User
 
Join Date: Jun 2009
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Default change string to datetime in ado.net

hi everyone
I have a number of tables (8) that i need to insert data into at almost the same time(thats how my user will see it). I have a form with tabpages they use to insert data into the tables.
I am using an insert store procedure to aid with all this. Now my problem is that i have a few datetimepickers my user uses to insert dates into the respective attributes,their data type is date. when i try to save the data i get the following error.
'Failed to convert parameter value from string to datetime'

I have also attached a sample of one of the datetimepickers i am using. Please help me sort this out.An example will be appreciated.

saveCommand.Parameters.AddWithValue("A_BOOKDATE", abookdatePicker1.Text).DbType = DbType.DateTime


Many Thanks in advance

Last edited by slake; July 5th, 2009 at 03:48 PM.. Reason: spelling mistake
Reply With Quote
  #2 (permalink)  
Old July 5th, 2009, 05:50 PM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi Slake,

Have you tried changing the code to use abookdatePicker1.Value instead, which gets the value as an actual DateTime?
There isn't always a direct link between what format a .NET control displays a date in and what SQL Server or another database expects it to be passed in as, so it is always best to pass an actual DateTime to the Parameter.Add methods whenever possible.

HTH
Phil
Reply With Quote
The Following User Says Thank You to philip_cole For This Useful Post:
slake (July 7th, 2009)
  #3 (permalink)  
Old July 7th, 2009, 03:54 PM
Authorized User
 
Join Date: Jun 2009
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Default Values duplicated in database

hi
i got it to work but im now faced with a new problem.
I have a procedure that handles all my inserts into the system. I make these inserts into the database using a Vb form. Now my problem is that when i click the save button the values a duplicated in the database. I cannot quite understand why thsi is the case.

Do you by any chance know why this so? Please advise. Look forward to hearing from you.

Kind Regards

Slake
Reply With Quote
  #4 (permalink)  
Old July 8th, 2009, 04:01 AM
Friend of Wrox
Points: 793, Level: 10
Points: 793, Level: 10 Points: 793, Level: 10 Points: 793, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

Slake:

I just had a thought or two on your duplication of records, but you will have to read how to translate to VB.NET-ese. Check on the following:
  • The state of the Cache especially after you have process that form page;
  • Review how the rows are processed automatically. I can't remember the code u submitted in an earlier thread.
Just a thought or two.
__________________
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.
Reply With Quote
The Following User Says Thank You to peace95 For This Useful Post:
slake (July 8th, 2009)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert String to DateTime SimoNWellborne C# 3 October 11th, 2014 02:24 AM
How to change DateTime to U.S format? chobo2 ASP.NET 3.5 Basics 3 March 8th, 2009 02:56 PM
convert string to datetime in VB.net lisabb ASP.NET 2.0 Basics 3 June 19th, 2007 06:52 AM
How to convert a string in DateTime elena SQL Language 6 March 29th, 2006 06:59 PM
How to convert a string in DateTime elena ADO.NET 3 July 24th, 2003 04:31 PM



All times are GMT -4. The time now is 07:10 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.