Reputation: 121
I have an dollar amount in my database column. I can get it to place the data in a column based on whether or not the amount is negative or positive, but it produces "0.00" in the False column. How do I get it to leave that column blank?
The code that I have is as follows.
Dim query = From t In ds.HNBSavings
Order By t.Date Descending, t.Id Descending
Select t.Id, t.Date, t.Desc, Debit = If(t.Amount >= 0, t.Amount, 0), Credit = If(t.Amount < 0, t.Amount, 0)
dgBank.ItemsSource = query.ToList()
So the results are 5.0000 under debits if it's positive and 0.0000 under credits the functionality works, but the results are a little difficult to read.
I have tried changing the false declaration to Null, and it works but returns a 1.0000 in the false column. Changed it to empty string " ".ToString(), but get a runtime exception.
Thanks for the help in advance.
Upvotes: 1
Views: 2618
Reputation: 69260
You are returning numbers from your if(...)
statements and there is no such thing as a blank number. The closest is 0, which is why you see that result. Return strings instead that can show an empty string.
Dim query = From t In ds.HNBSavings
Order By t.Date Descending, t.Id Descending
Select t.Id, t.Date, t.Desc, Debit = If(t.Amount >= 0, t.Amount.ToString(), ""), Credit = If(t.Amount < 0, t.Amount.ToString(), "")
dgBank.ItemsSource = query.ToList()
Upvotes: 1