StrataFrame Forum

BO Mapper DateTime C# Settings Issue

http://forum.strataframe.net/Topic28542.aspx

By Jeff Pagley - 9/30/2010

I have been using Strataframe/VB.NET for some time now.  But I have been ask to develop an C#/ASP.NET Web app.  So I am new to all that.  I am trying to setup my field settings in the BO Mapper where I am assigning for my date fields the value of #1/1/1800# for Return Alternate on Null / Set Null on .... option.  C# code generated shows the compiler error 'Preprocesor directives must appear as the first non-whitespace character on a line.' for the following code:

if (value != #1/1/1800#)

What is wrong?  Also, in addition to this, is there anything else I need to be aware of when using C# vs VB.NET is setting up the BO Mapper stuff?

Thanks,

Jeff
By Edhy Rijo - 9/30/2010

Hi Jeff,

Instead of using a literal in the Return Alternate on Null, try something like this:
New DateTime(1800, 1, 1)
By Ivan George Borges - 9/30/2010

I think you could also use DateTime.Parse("1/1/1800 00:00:00")


Here is a good comparison chart that could be handy for you:

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
By Greg McGuffey - 9/30/2010

The primary concept to understand is that the BOMapper is going to put whatever you type into the replacement value directly into code. Thus it must be valid for the language being used by the BO.  VB.NET has the date literal (#1/1/1800#) but C# does not. I use the method Edhy suggested myself, though it has to be valid C# so it has to be:

new DateTime(1800, 1, 1)


No semi-colon needed as it is inserted into lines of code, but the new keyword is lower case in C#.
By Jeff Pagley - 9/30/2010

Thanks Edhy/Greg that did the trick.  BTW Ivan the comparison chart is very helpful.  Thanks!
By Edhy Rijo - 9/30/2010

Your are welcome Jeff!
By Ivan George Borges - 9/30/2010

That is great, Jeff. Hope it helps. Wink
By Greg McGuffey - 9/30/2010

Glad it helped Jeff!  And I used the chart Ivan posted a lot when I was learning C# after having programmed in VB.NET for a couple of years.