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:
01398754
Views:
51
Is it OK or not really a good code
string strOrderNo = this.txtOrderNo.Text;
                        int? OrderNo;
                        if (strOrderNo.Equals(String.Empty))
                            OrderNo = null;
                        else
                            OrderNo = Convert.ToInt32(strOrderNo);

                        _dtOrder = biz.Find(OrderNo, this.dtgStartDate.Value, this.dtgEndDate.Value);
>>Hi everybody,
>>
>>Sorry, how can I convert this
>>
>> _dtOrder = biz.Find(this.txtOrderNo.Text, this.dtgStartDate.Value, this.dtgEndDate.Value);
>>
>>My biz object has this signature Find(int? OrderNo, datetime? StartDate, datetime? EndDate)
>>
>>I tried to add (int?) and (int) in front of the OrderNo.Text, but it doesn't compile.
>>
>>Thanks a lot in advance.
>>
>>UPDATE. This seems to compile
>>
>>_dtOrder = biz.Find(Convert.ToInt32(this.txtOrderNo.Text), this.dtgStartDate.Value, this.dtgEndDate.Value);
>>
>>Am I right?
>
>If this.txtOrderNo.Text is empty, Convert.ToInt32() will throw an exception. You'll probably want to add some code which checks that before you try converting it. You'll have to decide if empty means 0 or it means 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