How to test for dbNull field on OLEDB update of VFP table



I seem to be running in circles here. I decided to use a datetime field in
a VFP DBF table (8 bytes, type DATE) to handle concurrency conflicts. So I
altered the existing table to add a LASTUPDT field of type DATE. Initially
all values in this column are NULL (as displayed in the browser window of
VFP).

In VB.NET I'm using OLEDB with the vfpoledb.1 provider. I'm also using a
dataset to perform all my updates. The problem comes in how to specify the
UPDATE statement so that it accounts for the possibility of the "old" value
of LASTUPDT being NULL. Remember that oledb with the vfp provider requires
all replacement values to be passed as parameters. So my update stmt looks
like this:

cmd = New OleDbCommand("update rolodex set rphone = ?, lastupdt = ? where
name = ? and lastupdt = ?", dconnTele)
cmd.Parameters.Add("@rphone", OleDbType.VarChar, 13, "rphone")
cmd.Parameters.Add("@lastupdt", OleDbType.Date).Value = Today
cmd.Parameters.Add("@name", OleDbType.VarChar, 30, "name")
cmd.Parameters.Add("@lastupdt", OleDbType.Date, 8, "lastupdt").SourceVersion
= DataRowVersion.Original
daTele.UpdateCommand = cmd

The problem is that it doesn't work. It updates 0 rows. I've narrowed it
down to the WHERE stmt comparing the lastupdt fields. So, to help isolate
the problem, I tried to do an update manually using the EXECUTENONQUERY
method like this:

cmd = New OleDbCommand("update rolodex set rphone = ?, lastupdt = ? where
name = ? and (lastupdt = ? or lastupdt = ?)", dconnTele)
cmd.Parameters.Add("@rphone", OleDbType.VarChar).Value =
dsChanged.Tables("rolodex").Rows(0).Item("rphone", DataRowVersion.Current)
cmd.Parameters.Add("@lastupdt", OleDbType.Date).Value = Today
cmd.Parameters.Add("@name", OleDbType.VarChar).Value =
dsChanged.Tables("rolodex").Rows(0).Item("name", DataRowVersion.Current)
cmd.Parameters.Add("@lastupdt", OleDbType.Date).Value =
dsChanged.Tables("rolodex").Rows(0).Item("lastupdt",
DataRowVersion.Original)
cmd.Parameters.Add("@lastupdt", OleDbType.date).Value = System.DBNull.Value

As you can see, I'm trying to test for lastupdt being an actual date or
trying to test if it's dbnull. I manually pre-loaded a record with a date
value, and if I update that record, everything works fine. If I try to
update a record where LASTUPDT is dbnull then the WHERE clause does not find
a match and 0 records are updated.

So the whole thing seems to be failing because I can't seem to pass a
parameter with a "null" value for the where clause to compare to the current
field (which is null also). I can't use the method ISNULL as was suggested
in some similar questions I found because the WHERE clause can't do a ISNULL
method, it has to do a straight comparison. (or so I believe).

If anybody understands what I'm asking for and has a solution I would be
very grateful for some help on this. I really don't want to be forced to
"pre-load" all of the fields to a date value (although I will if I must).
Seems like there should be a way to test for nulls in the where clause...
Thanks,
John


.



Relevant Pages

  • Re: How to test for dbNull field on OLEDB update of VFP table
    ... or lastupdt is null) ... >altered the existing table to add a LASTUPDT field of type DATE. ... > down to the WHERE stmt comparing the lastupdt fields. ... > update a record where LASTUPDT is dbnull then the WHERE clause does not ...
    (microsoft.public.vb.database.ado)
  • A Bug in VFP 9.0? - Error: 1808
    ... I have encountered a problem when upgrading several projects from VFP 8 up ... ORDER BY clause is invalid ... Run this query which works ok: ... Obviously if I had not been lazy in my naming convention then this problem ...
    (microsoft.public.fox.vfp.queries-sql)
  • A Bug in VFP 9.0? - Error: 1808
    ... I have encountered a problem when upgrading several projects from VFP 8 up ... ORDER BY clause is invalid ... Run this query which works ok: ... Obviously if I had not been lazy in my naming convention then this problem ...
    (microsoft.public.fox.programmer.exchange)
  • Re: XP Themes in older screens
    ... all I am doing is running generated SPR files. ... The color clause I ... I just read about a couple of nice things in VFP 8 and 9 which I'd like ... I have a project that contains 500 foxpro 2.6a screens ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Performance issues
    ... very key to optimizing performance with the Rushmore technology for VFP. ... This where clause will recognize that there exists an i index on the ... Only VFPOLEDB can call stored procedures. ...
    (microsoft.public.fox.vfp.dbc)