I am relatively new to .Net and SQL Server and I need to be able to do a boolean check on a DateTime datatype for a null value.
I am using the following statement which is clearly wrong as it returns an Int32 in my Visual Studio immediate window while debugging. I am using linq to call a stored procedure which interrogates a bunch of tables.
The markup that some of the result collection will be bound to look like this;
<asp:Image ID="imgAuthorised" ImageUrl='<%# (bool)DataBinder.Eval(Container.DataItem, "AuthorisedDate")?"/Horizon/Images/save16x16.png":"/Horizon/Images/delete16x16.png" %>' runat="server" ToolTip='<%# (bool)DataBinder.Eval(Container.DataItem, "AuthorisedDate")?"Authorised":"Not Authorised" %>' />
Depending on the boolean value of the collection returned then I want to display an appropriate image. Here is my attempt(ahem) to do an evaluation within the stored proc’
CASE WHEN dbo.Expense.AuthorisedDate is null THEN 0 ELSE 1 END as AuthorisedDate
I have tried casting this statement like so;
CAST(CASE WHEN dbo.Expense.AuthorisedDate is null THEN 0 ELSE 1 END as bit) as AuthorisedDate
Feel free to giggle at any school boy errors or poor understanding as I’m a dot net newb (hence the name :P) ha!
I would appreciate if someone could help me understand what I am doing wrong and what to do/avoid in future when attempting to do stuff like this.
TIA
dotnetnewb
what about extending your model? Your stored procedure (lets assume it’s called
GetMyData) will likely return an ISingleResult.If so, go to your DBML, view code (assuming this is a web application) and create a new partial class:
And then you should be able to:
<asp:Image ID="imgAuthorised" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "IsAuthorised")?"/Horizon/Images/save16x16.png":"/Horizon/Images/delete16x16.png" %>' runat="server" ToolTip='<%# DataBinder.Eval(Container.DataItem, "IsAuthorised")?"Authorised":"Not Authorised" %>' />Alternatively, you can piggyback onto the OnItemDataBinding event and do the work in there, though the above would be the easier path I’d think.
Cheers,
Terry