|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Please help with an 'impossible' error!I am getting the following runtime error: "Cannot perform '=' operation on System.DateTime and System.Int32." But I can't understand where the Int32 is coming from!! The code is: Drv.BeginEdit() Drv("Editor") = Me.Recorder.Text Drv("CompletedDateTime") = Me.DateTime.Value Drv.EndEdit() So, I am setting the value of the CompletedDateTime column to the value of a DateTime control on the form. Strange, because in the code (on a different table, but the same DateTime control it works perfectly: Drv("DateTime") = DateTime.Value So - why is there a problem, and where is the System.Int32 it is talking about?!? When I debug during runtime, the value returned from Me.DateTime.Value is #12/01/2006# and so on. Even when I rewrite the code to: Drv("CompletedDateTime") = #12/01/2006# It still causes the same error! I'm tearing my hair out here.. any help much appreciated. Thanks! Jimmy,
Can you show us how you have instansed "your" object "DateTime" and what it is. The drv("Editor") item shows you a column with type DateTime with its default value. In another way tell us what you want to achieve. Cor <jimmy***@gmail.com> schreef in bericht Show quoteHide quote news:1141109125.265784.134350@z34g2000cwc.googlegroups.com... > Hi all, > > I am getting the following runtime error: > > "Cannot perform '=' operation on System.DateTime and System.Int32." > > But I can't understand where the Int32 is coming from!! > > The code is: > > Drv.BeginEdit() > Drv("Editor") = Me.Recorder.Text > Drv("CompletedDateTime") = Me.DateTime.Value > Drv.EndEdit() > > So, I am setting the value of the CompletedDateTime column to the value > of a DateTime control on the form. > > Strange, because in the code (on a different table, but the same > DateTime control it works perfectly: Drv("DateTime") = DateTime.Value > > So - why is there a problem, and where is the System.Int32 it is > talking about?!? > > When I debug during runtime, the value returned from Me.DateTime.Value > is #12/01/2006# and so on. > > Even when I rewrite the code to: > Drv("CompletedDateTime") = #12/01/2006# > It still causes the same error! > > I'm tearing my hair out here.. any help much appreciated. > > Thanks! > Thanks for the reply,
"CompletedDateTime" is a column in an SQL database, of type Smalldate. "Editor" is just a string (and it is working fine).. Me.DateTime.Value refers to a Winforms DateTimePicker control. Jimmy,
I would not name a DateTimePicker control DateTime, it is probably asking for troubles. DateTime is one of the main Types. Cor <jimmy***@gmail.com> schreef in bericht Show quoteHide quote news:1141118614.221357.130350@z34g2000cwc.googlegroups.com... > Thanks for the reply, > > "CompletedDateTime" is a column in an SQL database, of type Smalldate. > "Editor" is just a string (and it is working fine).. > > Me.DateTime.Value refers to a Winforms DateTimePicker control. > Again, thanks for the ideas.. OK, I've changed the name of my Winforms
control to dtp1... but still no luck.. With some experimenting in my SQL database I located where the problem is. The "CompletedDateTime" field in the table is allowed to be null. When i first populated the table, I left this field NULL, and it is set as a 'not required' field. If I go manually and change the data in SQL server, from NULL to give it a date e.g. 12/2/2008 12:00:00AM it works perfectly, no errors! But when i edit the datarowview with Drv("CompletedDateTime") = Me.DateTime.Value well, it causes the error if the dataset field was previously NULL. if it was previously set to a date, it works fine. Would greatly appreciate some help!! Many thanks! Jimmy,
May I assume this is > Drv("CompletedDateTime") = Me.DateTime.Value Drv("CompletedDateTime") = dtp1.valueIf the type of drv is DateTime, than it should in my opinion no proglem. You can see this by messagebox.show(TheOriginalTable.DataColumns("CompletedDateTime").GetType.ToString) I hope this helps, Cor OK problem solved - thanks for all the help! I was about to completely
give up! In a previous section of code, I had the following: Dv.RowFilter = "Isnull(CompletedDateTime, -1) = -1" Now, I changed that to: Dv.RowFilter = "Isnull(CompletedDateTime, 01/01/0001) = 01/01/0001" And there are no problems. I wonder why though? I thought "Isnull" simply returned whatever value you set if the column is null? Is there any workaround, or do I always haveto use a ficticious date with Isnull? (e.g. do I have to set it as 01/01/0001, or can I use a string or something else??) Anyway thank you.
View Source from WebBrowser (2005)
Upgrading VB6 to .Net Distributing VB 2005 projects Help authoring tool for Windows app? OO & Interface question function to convert string to 1 dimensional array of long button in bold Getting primary key from new record instered into one table using ADO.net IIF in vb.net acts weird.. or is it me Using the && operator in generated JavaScript |
|||||||||||||||||||||||