Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
Old July 5th, 2009, 05:50 PM
Friend of Wrox
 
Join Date: Sep 2005
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
The Following User Says Thank You to philip_cole For This Useful Post:
slake (July 7th, 2009)
 
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
 
Old July 8th, 2009, 04:01 AM
Friend of Wrox
 
Join Date: May 2005
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.
The Following User Says Thank You to peace95 For This Useful Post:
slake (July 8th, 2009)





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





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