May 22, 2015

Recently, I had to login to a SQL Server to get some data but the pain was I had to login to remote desktop using a different windows username and then opening Sql Server Management Studio and then opening connection to the Sql Server in a different server. I was thinking this is just crazy and I would simply just want to connect to the sql server using my local Sql Server Management Studio.

May 18, 2015

C# Different ways to create a string

Strings, in C#, represents text as a series of Unicode characters. A string can be referenced as both "string" and "String" - string is basically an alias of System.String.  It can be created in a number of ways. In the simplest form, it can just be assigned or alternatively it can be created using the String's constructors. String, like other objects in .NET, can be assigned to null. Strings might look like and can be used like other variables like int or double but one important characteristics is that it is immutable - that is, once a String is created, it cannot be changed (so, when a string variable is re-assigned, behind the scenes, a new string is created and assigned to the variable).

The main difference between nvarchar and varchar column is in the character set of data that it can store. Varchar is single byte whereas nvarchar is double-byte and therefore nvarchar can store Unicode characters while varchar cannot.

May 15, 2015

To escape a single quote in Sql Server, use two single quotes. Note, don't use a double quote.

For example, the following SQL Script will give error.

All these methods Int32.Parse(), Convert.ToInt32(), and Int32.TryParse() ultimately does the same thing - convert a string to an integer. The main difference lies in what happens if the conversion does not succeed. With Int32.Parse(), exceptions are thrown if conversion does not work. With Convert.ToInt32() methods 0 is returned while parsing null, otherwise exceptions are thrown. With Int32.TryParse() method, no exception is thrown - it sets the correct value to an integer variable if conversion succeeds and at the same time returns a boolean value suggesting if conversion has succeeded.


Reference: Shahed Kazi at