Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How should I code this?
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01398722
Message ID:
01399148
Views:
62
>>>Hi,
>>>If Naomi has access to the biz layer source then, yes I'd agree, a better solution.
>>>An alternative with wider use might be to add a .ToNullableInt() extension method for String.
>>>Best,
>>>Viv
>>>
>>I do have an access to BL, so I may code it there. For the extension method I haven't done them yet, so I'm not sure how to implement it.
>
>The Extension method would be something like:
public static int? ToNullableInt(this string s)
>{
>    int result;
>    bool b = Int32.TryParse(s,out result);
>    return b ? (int?) result : null;
>}
Then anywhere this method is in scope you could use, for example:
string s = "12345";
>int? i = s.ToNullableInt();
Note the above implementation would return null for any string that doesn't translate to a valid int (null, string.empty, "123.45", "asd" etc.) which may no be exactly what you want. And I wouldn't bother to implement this unless you know it will have a wider use than in your original requirement....
>Best,
>Viv

Where exactly should I place this code?

I'm getting an error here right now

System.NullReferenceException was unhandled
Message="NullReferenceException"
StackTrace:
at IOTechno.SDC.Business.InventoryBiz.Find(String ItemNo, String description)
at IOTechno.SDC.Windows.OrdersEntryForm.DisplayItemInfo(String ItemNo)
at IOTechno.SDC.Windows.OrdersEntryForm.txtItemNo_LostFocus(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnLostFocus(EventArgs e)
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at IOTechno.SDC.Windows.Main.BDMain.Main()

The code is
  public InventoryDS.ItemsDataTable Find(string ItemNo, string description)  
        {
            if (ItemNo.Equals(string.Empty))
            { ItemNo = null; }

            if (description.Equals(string.Empty))
            { description = null; }
 
            ItemsTableAdapter ta = new ItemsTableAdapter ();             
            return ta.GetInventory(ItemNo, description);
        }
and I call it with oBiz.Find(ItemNo, null)
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform