tags:

views:

25

answers:

1

Hi..

I have table called Customers and this customer has Bank Details but Some customer they don't have,

When i Use Linq to sql it's Return Null value, like a below example Table

How to prevent this null into Default value 0 or String

Ex. Table

Customer ID   Name            bank name
-----------   ------          --------------
J0002         John            HSBC 
K0001         Kethy           SMC
L0003         Mike            Null
S0004         Lilie           Null

Thanks

A: 

Something like

var customers = (from c in Customers
                        select new Customer
                       (
                          c.CustomerId, 
                          c.Name, 
                          c.BankName ?? ""
                       )).ToList();

or

var result = Customer.Select(x => new
{
    CustomerId = x.CustomerId,
    Name = x.Name,
    BankName = x.BankName.HasValue ? x.BankName : ""
}).OrderBy(p => p.Name).ToArray();

could do the trick. It would be easier if you showed your current query.

Jonas Elfström
can send vb.net code please
Suhaibnm
I'm not really a VB.NET programmer but if you send your query I might be able to modify it to your needs.
Jonas Elfström
Check out `If(c.BankName Is Nothing, "", c.BankName)`
Jonas Elfström