I have a database with a table in which I store several values along with the zone to which it belongs, the date it is from, and the hour it is from. The table will get updated periodically, from a source that may contain both new and old data I already have, new data will be inserted, old data I already stored will be updated, since it may have changed from the time it was created and I need the newest possible.
I have no problem checking wether the zone and the hour already exists:
sql.CommandText = "select 'Y' from dual where exists (select * from mytable where hour= "+hour+" and zone='" + zone+ "')"
But If add the date to the equation it fails when it calls the ExecuteScalar method:
sql.CommandText = "select 'Y' from dual where exists (select * from mytable where hour = " + hour + " and zone = '" + zone+ "' and date_field = '" + datevalue + "')"
I have tried other methods before but none seemed to work, like doing a Select Count(*) and executing the reader or doing a merge sentence.
Any help is appreciated. I’m working on VB, .NET framework 3.5, and Oracle 10g.
The comparison must look like this in oracle:
Try this, if you want to keep the string version, but using a prametrized query as Magnus has shown, circumvents the date representation problem:
Note:
datevalueis assumed to be aDateTime.