Windows Develop Bookmark and Share   
 index > Windows Forms General > Failed to convert parameter value from a String to a DateTime.
 

Failed to convert parameter value from a String to a DateTime.

Well I'm developing a data driven application in which I've created a dataset using to datatables called "PartyMaster" and "LedgerMaster". Basically both the tables have same structure but different uses. So in the SqlDataAdapter i've wrote same commands (Insert,Update etc.) for both the tables but whenever I insert or update the PartyMaster table it works fine but the LedgerMaster table is creating trouble when i try to update a row (creating new rows is working fine though). It always throws an exception called "Failed to convert parameter value from a String to a DateTime" I mean i had never such problems with my code. I'm quite experienced with the DateTime datatype and the PartyMaster table has the same definitions at each and every level and its working great. I copied and pasted all the command, parameter definitions from PartyMaster to LedgerMaster to make them identical but still I'm getting the exception and yes I've rebuild the application several times. So if anybody have something for me then please help me.
Martene  Monday, October 05, 2009 3:14 PM
Well well well,
I think i should laugh at my self and so do you. Actually there were two SqlDataAdapter definitions for the LedgerMaster table and there was a typo in both of them and I was just looking at the first definition and as the matter of fact the second definition was in use in that context so sometimes a little typo can trouble us so much. 
By the way thank you all for being with me. And Happy Deepawali (the celebration of light and prosperity).
  • Marked As Answer byMartene Tuesday, October 06, 2009 7:39 AM
  •  
Martene  Tuesday, October 06, 2009 7:39 AM
Is there a field in LedgeMaster that is defined as a datatime?

What does the command look like that is generating the error?


www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Monday, October 05, 2009 4:07 PM

What database engine are you using ?

Can you post the code you use to create and execute the commands ?

If you are building dynamic sql as strings makes sure you format the date time values as yyyymmdd HH:nn:ss to ensure Sql Server copes with them properly. If you are using parameterised queries but putting strings containing date times into the parameters, change your code so you're actually passing DateTime values.

If you can post the code we might be able to suggest other problems.

Yort  Tuesday, October 06, 2009 2:02 AM
Well I'm using Sql Server 2005 and I'm using parameterized queries and supplying 'Now' (not a string) as the datetime value and it's working fine with the PartyMaster table but generating errors when used with the LedgerMaster table.
Martene  Tuesday, October 06, 2009 5:52 AM
Well well well,
I think i should laugh at my self and so do you. Actually there were two SqlDataAdapter definitions for the LedgerMaster table and there was a typo in both of them and I was just looking at the first definition and as the matter of fact the second definition was in use in that context so sometimes a little typo can trouble us so much. 
By the way thank you all for being with me. And Happy Deepawali (the celebration of light and prosperity).
  • Marked As Answer byMartene Tuesday, October 06, 2009 7:39 AM
  •  
Martene  Tuesday, October 06, 2009 7:39 AM

You can use google to search for other answers

Custom Search

More Threads

• Autocomplete textbox souce as webservice?
• Help with start up of VS2005 app
• Custom sliding panel with buttons
• How to run Function under different user?
• Merging ToolStip toolbars
• How to develop Data Entry Windows Application?
• Scrolling in a custom combobox
• Get the format of the selected html text in a web browser control
• How to drag & drop columns header to group by that columns in DataGridView
• How to resize form?