Difference between String.Empty, Empty Quotes and String.length

Hi

A few days back when I was working with string. At many point of time I had to make a checking for empty string. I started thinking about the difference between “” and string.empty. and which one is a better way to check if the string is empty or not.

The difference between string.Empty and “” is very small. String.empty will not create any object while “” will create a new object in the memory for the checking. Hence string.empty is better in memory management.

But the comparison with string.length == 0 will be even faster and the better way to check for the empty string. And I also have a bias for checking with string.length in this case. But do not forget to make a checking for null value if you are also expecting null value in the comparison.

Happy coding
Vikram


Finding the first not null argument from coalesce function

Hi

Yesterday I was writing a stored procedure, where I had to fetch data based on the Null condition. What I had to do was make a null checking in the field. If the value is null then I would take another column or else the current. The same logic would apply for multiple columns.

Hence in one query I had to check 5 columns to fetch the data. At first I had 2 things in mind, Use the case condition to fetch data. Another thing that came to my mind instantly was the isNull function. A simple example would be

Isnull(column1, Isnull(column2, Isnull(column3, Isnull(column4,0))))

Continued...


Datetime calculation in SQL Server

Hi,

Last few days I have been working a lot in SQL server with DateTime data type and learned some simple but good tricks. One of the things that I learned was the month and year function. Normally when we have to find the month or year from a date variable or column we use the datepart function where we also need to pass what date part we need.

The month and year function do nothing special. They also return the month and year for the given date function. So what’s good about it? For me it only makes the query look easier to read and understand.

What do you do when you need the data for the latest month-year and we are storing month and year in the database instead of storing the date? I know we can concatnate the two columns with the day as 1 and get the date and compare them. Another easy way out can be to multiply the year with 12 and adding the month column to it. This will not have the over head of creating a date inside a

Continued...

New emerging technology from Microsoft Photosynth

Hi

Photosynth is an amazing new technology from Microsoft Live Labs that will change forever the way you think about digital photos.

With Photosynth we can walk or fly through a scene to see photos from any angle. Seamlessly zoom in or out of a photo whether it's mega pixels or gigapixels in size. See where pictures were taken in relation to one another. Find similar photos to the one you're currently viewing. Send a collection - or a particular view of one - to a friend.

Have a look yourself

http:////labs.live.com//photosynth//

Vikram


Apple brings out a browser for Windows

Hi

So the browser war is really heating up. Till now we had to worry only about IE 6(Many people still uses this), IE 7, Fire fox, and Opera on windows. Now there is a addition. Apple has come up with a version of safari for windows.

So this means we need to test the web application in one more browser. I am very sure that there will be many differences in the safari in MAC and safari in windows. So if you are thinking that testing in one of the safari browser (either MAC or windows) will work for both, than you might be up for a toss. I have already heard of a few mismatch between safari in the two operating system.

But whatever happens this promises more fun in the browser war, and most probably some very good new invention in the browser. After all there are 3 people fighting for the same space.

Thanks
Vikram


Keeping the scroll position of a div after post back

Hi

A few days back I came up with an interesting requirement. I was working on a page, which had a scrollable div. The problem was that after the post back the div would loose its scroll position. Now when there is a lot of data it is very inconvenient for the user to again scroll back to the position where he was before the post back.

One of my colleagues helped me out with the solution. The solution was quite simple. We saved the value of the scroll in a hidden variable. This was done on the onscroll event of the div. On the page load event of the page we again set the scroll of the div to the value saved in the hidden variable. That’s all. Here is a simple code to show the actual working.

<body onload="SetVikScroll()">
    <form id="form1" runat="server">
        <div id="VikramDiv" onscroll="saveScrollPos();" style="height:50px; width:100%;

Continued...

What is the difference between a delegate and an event?

Hi

A few days back one of my colleague got confused with the difference between a delegate and event. We can do the same thing with both a delegate and an event. There only seems to be a syntactical difference between the 2. So he searched and found the answer to the fact.

Here is the difference between a delegate and an event.

Delegate:

public class VikramDel

{

public delegate void VikramExampleDelegate(int num1,string str1);

public VikramExampleDelegate VikramDeleageteCallback;

}

Event:

public class VikramEvent

{

public delegate void VikramExampleEvent(int num1,string str2);

Continued...


SQL Server and different types of lock

Hi

There are different types of lock in SQL Server 2000 and 2005. These locks are applied in different situations. Here is the list of locks and the situation for the locks.

SHARED - This lock is applied for read operation where the data is not updated. A good example would be the select statement.

UPDATE – This locked on those resources that can be updated. This lock prevents the common form of dead lock that occurs when multiple sessions are locking the data so that they can update it later.


EXCLUSIVE - Used for data-modification operations, such as INSERT, UPDATE, or DELETE. Ensures that multiple updates cannot be made to the same resource at the same time.

INTENT - Used to establish a lock hierarchy. The different types of intent locks are: intent shared, intent exclusive, and shared with intent exclusive.

SCHEMA - Used when an operation dependent on

Continued...
 
Copyright © 2006 - 2012 Vikram Lakhotia