Monday, August 27, 2012

SQL Delete current database

I need to delete my current database which I am using it , I googled around and found this answer:

http://sqlserver2000.databases.aspfaq.com/how-do-i-drop-a-sql-server-database.html

ALTER DATABASE myDataBase
    SET SINGLE_USER
    WITH ROLLBACK IMMEDIATE

DELETE DATABASE myDataBase 

Sunday, August 26, 2012

Thursday, August 16, 2012

C# difference between StringBuilder and String Object

The most common operation with string is concatenation, and this has to be performed very efficiently.
When we use String objects to concatenate two strings , then a new copy of string object is created in memory by adding two objects , and the old string object is deleted.

So we use StringBuilder to do it in a effective way, here the concatenation is done on the exsisting  string, hence the insertion is faster. Concatenation is done using Append() method

C# difference between XmlDocument.Load() and XmlDocument.LoadXml()

XmlDocument.Load() is used to load a stream, or from xml file path.
XmlDodument.LoadXml() literally loads content of xml.


C# convert document to string type.

Hi Guys,
There was a situation in my project where I have to convert a xml document to string type, initially I though it is very difficult, and later I felt  it is a cake-walk actually!, the below code snippet shows how to achieve it:



  • First you create a XmlDocument object, then you load the content of the xml document file into the object , where 'file' is the path of the xml file.
  • Create a stringwriter , and save the contnet of xmldocument object into the string writer 'sw'
  • Convert the string writer 'sw' to string and store it in a string variable.

Thursday, August 2, 2012

C# Shallow Copy and Deep Copy

Difference between null and String.Empty

1. string statement=null : means no object exists; null is not a value, it is a state indicating that object value is unknown or does not exists.

2. string statement = String.Empty : use of string.Empty doesn't create any objects  while "" creates a string object. So using string.Empty is better than using "" because every time you use "", it creates a new string while string.Empty just reference s string in memory that is created by default.

Wednesday, August 1, 2012

Understanding Reflection and static constructor

Hi .net newbies,
This post is mostly for you !!, to understand what  Reflection and static constructor really mean ,and when are they used in  .net projects.

You would have learnt what does .net reflection and static constructor mean , 
You may say reflection is :  The process of obtaining information about the assemblies and the types defined within them ,and creating and invoking and accessing type instance at run time and
You may say static constructor is used to initialize any static data or to perform a certain action that needs to be performed once.

So when do you use Reflection or static constructor, the below picture answers the question: