May 2005 - Posts

Custom CheckDBNull function in Whidbey using Generics.

In .NET 1.x, most of you would have created a utility function for doing the following two things

  • Check for dbnull 
  • Typecast the value to required data type or return the default value in case of dbnull. 

For example,     

// return default value for integer if the object is null

            public int DBCheckforInt(object i)

            {

                  if (i == System.DBNull.Value)

                        return 0;

                  else

                        return (int)i;

            }

 

            // return default value for decimal if the object is null

            public double DBCheckfordouble(object o)

            {

                  if (o == System.DBNull.Value)

                        return 0.0;

                  else

                        return (double)o;

            }

 

Note: For performance reason, you need to use System.DBNull.Value instead of using IsDBNull() function to check for dbnull. More details here.

Major disadvantage with this approach is, we need to create a function for each datatype that we require to check for dbnull. However, the logic is same for all the datatype. In whidbey, generics helps us to solve this kind of problem i.e. you can can pass data type as parameter to that function. In that function depending upon the datatype, return the default value for that datatype or typecast and return the value.  For example, same utility function in whidbey will be

 

public static T DBNullCheck<T>(Object obj)

            {

                  return obj == System.DBNull.Value ? default(T) : (T)obj;

            }

 

In whidbey, it is one function for all the data types. default is the keyword in whidbey returns the default value for the specified datatype.  To know more about genercis, check out these articles on generics,

    1. CLR and Language Enhancements in Whidbey
    2. Generics Internals

One problem with this method is, for String it returns default value as null. In some cases, we might have String.Empty as default value for String. In those cases, this method might not be useful. But for all other primitive data types, this method will work.

 

with 4 Comments

Beginners Guide for Whidbey Express Products

 Absolute Beginner's Video Series to Visual Studio 2005 Express Editions

This video series is designed specifically for individuals who are interested in learning the basics of how to create applications using Visual Basic 2005 Express Edition and Visual C# 2005 Express Edition. This includes over 10 hours of video-based instruction that walks from creating your first "Hello World" application to a fully functioning RSS Reader application.

Visual Web Developer 2005 Express Edition Beta 2 Guided Tour

This guide will help you to learn some of the key features in ASP.NET 2.0 using Visual Web Developer 2005 Express. The Guided Tour is not intended be a comprehensive overview of VWD.  However, after completing the Guided Tour you will be well on your way to building your own sophisticated Web sites without writing any code

 

 

with 0 Comments

Changes in VB.NET Code Snippet Editor

From beta2, VB.NET Code Snippet Editor is available as a standalone windows application. You can download it from here. If you are not aware of Code Snippet Editor, it is a  Windows Forms application with UI for creating, editing, testing VB code snippets. If you want to know more about code Snippets, check out my articles "Code Snippets in VB.NET 2005" Part1 and Part2 

Actually, during pre beta, this snippet editor was integrated with VS.NET 2005. You can invoke this editor from code editor by selecting Create Snippet menu option from context menu.  I have mentioned about this in my article "Code Snippets in VB.NET 2005".  Now it is moved out of VS.NET 2005. I dont know why MS has done this, I feel it will be better if VB.NET Code Snippet Editor comes along with IDE. I am trying to integrate this tool with VS.NET IDE. if i succeed, i will post the details.

with 0 Comments

Do you have any queries on Yukon?

If you have any unanswered queries on Yukon, here is the chance for you to get your queries answered. CIOL, a leading magazine group has a column "Ask the Experts" which is aimed at bridging the gap between subject experts and developers. For this month, my close friend Vinod is hosting this column. He is a Microsoft MVP in SQL Server. He answers any queries on SQL Server 2005(Yukon), so if you have any question on yukon.. Post it here. He will surely get you the answers....

He is a very cool guy, if you post to him personally also he will answer your questions. But if you post your question in this column, it will help others  who is having similar queries.

 

with 0 Comments

Refactoring support in VB.NET 2005

One of the important features that was missing in VB.NET 2005 was refactoring though "Rename" capability was there.. But now Microsoft joined with Developer Express Inc and released a free plugin  "Refactor! for Visual Basic 2005 Beta 2" to support refactoring. This tool supports following refactoring operations,

  1. Reorder Parameters
  2. Extract Method
  3. Extract Property
  4. Create Overload
  5. Surrounds With (Not available in BETA 2 release)
  6. Encapsulate field
  7. Reverse Conditional
  8. Simplify expression
  9. Introduce Local
  10. Introduce constant
  11. Inline Temp
  12. Replace Temp with Query
  13. Split Temporary Variable
  14. Move initialization to declaration
  15. Split initialization from declaration
  16. Move declaration near reference

To know more about this free plugin, check out this web page. This refactor plugin can be downloaded from the same location.

with 0 Comments

VSTS Class Diagram format is changed in Beta2

Internally VSTS Class Diagrams(*.cd) are stored as xml file. Its format is changed in Beta2 from Beta1. So if any of you have created class diagram with previous release and if you face any problem while opening the class diagram in beta2. Then run use this utility to convert your class diagram to beta2 format.

I have few class diagrams for my current project, it opened in beta2 without any issues. Probably my class diagrams didnt use the feature that requires changes..

 

with 0 Comments

Update on MVP Asia Regional Summit

Like its theme "Get Connected", it was great oppurtunity to meet most of the fellow MVP's around Asia. Around 40 MVPs from India attended it. I would say it was more fun filled event then a technical event.  If you look at this snap, you will get to know....

(I just flicked this photo from MVP Intranet site...)

We enjoyed a lot and the event was very well organized. Only part that can be improved in the future summits is level of technical sessions. Most of the sessions were at 200 levels, i feel they should have taken few 400 level sessions. Session on Office12 was very interesting session  (i cant talk more on this, as it is covered under NDA).

Singapore is a very nice place to visit, especially for shopping. We went to Jurong Birdshow, night safari in Singapore Zoo and a lake side bar.. Then we went to few shopping malls Sim Lim Square, Mustafa and few shops in Orchard road.

Unfortunately as i mentioned in my previous blog, I didnt do much shopping. I got few stuff for my friends.. Smartphone is not cheap in Singapore as i expected, especially XphoneII. Therefore, I decided to buy it in India itself.

All in all, it was a great event. Expecting more events like this in future.

with 0 Comments