Please help with an 'impossible' error!

J

jimmy84c

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!
 
C

Cor Ligthert [MVP]

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
 
J

jimmy84c

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.
 
C

Cor Ligthert [MVP]

Jimmy,

I would not name a DateTimePicker control DateTime, it is probably asking
for troubles.

DateTime is one of the main Types.

Cor
 
J

jimmy84c

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!
 
C

Cor Ligthert [MVP]

Jimmy,

May I assume this is
Drv("CompletedDateTime") = Me.DateTime.Value
Drv("CompletedDateTime") = dtp1.value

If 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
 
J

jimmy84c

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top