Link to home
Start Free TrialLog in
Avatar of tkrems
tkrems

asked on

How to check against an empty FoxPro date field like " / / " in c#?

Hi to all,

I have a FoxPro dbf field of type Date and Width 8. This is imported to a DataTable using "CAST(YEAR(MASCH.baujahr) AS CHARACTER(4)) AS zusaetze5". In FoxPro the field looks like "  /  /    ".  What value is this from a c# view? How can I check against it?

thanks in advance
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

Does it matter? If you compute YEAR() of an empty date you get 0. So everywhere you get 0 in zusetze5 the original foxpro baujahr date was empty. Unless you have any machines built in year 0. Your code will not error because of an empty date.

The function to check for empty is EMPTY(), so eg you can.

SELECT ... CAST(YEAR(MASCH.baujahr) AS CHARACTER(4)) AS zusaetze5 ... FROM ... WHERE NOT EMPTY(MASCH.baujahr)

What may be problematic is MASCH.baujahr being NULL. But you can check against that with WHERE NOT (MASCH.baujahr IS NULL)

Bye, Olaf.
Avatar of tkrems
tkrems

ASKER

Sorry, Olaf. I want to check the field's value in c#, not in sql.
That's what I want to do:

                if (row[6].ToString().Trim() == "" | row[6].ToString().Trim() == "/  /")
               {
                   MessageBox.Show (row[6].ToString().Trim());
                   row[6] = "k.A.";
                    // row[6] is 'zusaetze5 (year)'
               }

Open in new window

SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tkrems

ASKER

Thank you both, was a problem with the OleDbDataReader.