Salakhetdinov Shamil
mcp2004 at mail.ru
Mon Apr 6 00:28:22 CDT 2009
Hi Gustav,
Thank you for your code review and proposal: I have changed dataset's Customer table Region field property to return null value and I have changed code in the OrdersForm - it looks better now - two+ times less of code lines. New code is committed to our server.
--
Shamil
-----Original Message-----
From: "Gustav Brock" <Gustav at cactus.dk>
To: <dba-vb at databaseadvisors.com>
Date: Sun, 05 Apr 2009 23:57:22 +0200
Subject: [dba-VB] SCRUM: Null value in DataTable
> Hi Shamil
>
> In your OrdersForm you write:
>
> /// <summary>
> /// Custom class to get Customer row attributes.
> /// This class is required to suppress exceptions
> /// caused by DbNull values of row fields.
> /// Note: if you know better method to workaround this
> /// issue please make a change here but leave the old code
> /// cpmmented. Thank you.
> /// </summary>
> private class customerAttributes
> {
> private Northwind.NET.FE.Datasets.OrdersFormDataSet.CustomerRow _row;
> public customerAttributes(OrdersForm form, int customerId)
> {
> Northwind.NET.FE.Datasets.OrdersFormDataSet.CustomerRow row =
> form.ordersFormDataSet.Customer.FindByID(customerId);
> _row = row;
> }
> public int? ID { get { try { return _row.ID; } catch { } return null; } }
> public string Name { get { try { return _row.Name; } catch { } return null; } }
> public string Address { get { try { return _row.Address; } catch { } return null; } }
> public string Region { get { try { return _row.Region; } catch { } return null; } }
> public string City { get { try { return _row.City; } catch { } return null; } }
> public string PostalCode { get { try { return _row.PostalCode; } catch { } return null; } }
> public string Country { get { try { return _row.Country; } catch { } return null; } }
> }
>
> I haven't tested it here, but until now I have managed this by selecting properties of each field/column in question (in the view of the xsd file), pick property NullValue and change the value from the default value of (Throw exception) to (Null).
>
> This can still cause trouble in the code. But to avoid that, a property is created for these colums, IsColumnNull, as well as a method to set it to Null, SetColumnNull().
>
> /gustav
>
>
> _______________________________________________
> dba-VB mailing list
> dba-VB at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vb
> http://www.databaseadvisors.com
>