p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > .NET > Other .NET > ADO.NET
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 5th, 2009, 04:47 PM
Registered User
Points: 42, Level: 1
Points: 42, Level: 1 Points: 42, Level: 1 Points: 42, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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 04:48 PM. Reason: spelling mistake
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 5th, 2009, 06:50 PM
Friend of Wrox
Points: 837, Level: 11
Points: 837, Level: 11 Points: 837, Level: 11 Points: 837, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 151
Thanks: 2
Thanked 32 Times in 32 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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, 04:54 PM
Registered User
Points: 42, Level: 1
Points: 42, Level: 1 Points: 42, Level: 1 Points: 42, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 8th, 2009, 05:01 AM
Friend of Wrox
Points: 741, Level: 10
Points: 741, Level: 10 Points: 741, Level: 10 Points: 741, Level: 10
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 211
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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



All times are GMT -4. The time now is 04:37 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc