Difference between Destructor, dispose and finalize method

Difference between Destructor, dispose and finalize method

Destructor They are special methods that contains clean up code for the object. You can’t call them explicitly in your code as they are called implicitly by GC (Garbage Collector). In C# they have same name as the class name preceded by the "~" sign. Like- class MyClass { public MyClass () { } ~MyClass () { } } Dispose These are just like any other methods in the class and can be called explicitly but they have a special purpose of cleaning up the object. In the dispose method we write clean up code for the object. It is important that we freed up all the unmanaged resources in the dispose method like database connection, files etc. The class implementing dispose method should implement IDisposable which is inherited by interface and it contains GC.SuppressFinalize method for the object it is disposing if the class has destructor because it has already done the work to clean up the object, then it is not necessary for the garbage collector to call the object's Finalize method.
Using DataList control display multiple records per row in an ASP.NET

Using DataList control display multiple records per row in an ASP.NET

DataLists are usually used to display HTML format in rows and column. We can customize the DataList layout through its RepeatColumns and RepeatDirection properties, which, respectively, indicate how many columns are rendered and whether those items are laid out vertically or horizontally. The RepeatDirection property can accept one of two values, that is, Vertical or Horizontal. The RepeatDirection is Vertical by default. RepeatDirection="Horizontal" A DataList control is useless without templates. A template is a combination of HTML elements, controls, and embedded server controls, and can be used to customize and manipulate the layout of a control. You can also customize the DataList control at run time using the ListItemType property in the ItemCreated event You can also do the same at run time by specifying your desired layout using the RepeatLayout property of the DataList control DataList1.RepeatLayout = RepeatLayout.Flow
Date and Time Formatting Scripts in Management Studio Query Editor (SQL Server)

Date and Time Formatting Scripts in Management Studio Query Editor (SQL Server)

-- Get date only from datetime - QUICK SYNTAX SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, CURRENT_TIMESTAMP)) -- 2016-10-23 00:00:00.000 ------------ -- SQL Server T-SQL date & datetime formats - Gregorian calendar - Christian calendar -- getdate() / CURRENT_TIMESTAMP(ANSI) returns system date & time in standard format -- SQL datetime formats with century (YYYY or CCYY format)- sql date & time format SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM (or PM) -- Oct 2 2010 11:01AM SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy - 10/02/2010 SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd - 2010.10.02 SELECT convert(varchar, getdate(), 103) -- dd/mm/yyyy SELECT convert(varchar, getdate(), 104) -- dd.mm.yyyy SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy
EXCEPT Clause in SQL Server

EXCEPT Clause in SQL Server

The Except Operator returns any distinct values from the left query that are not also found on the right query. The Except operator evaluates the output of two query expressions and returns the difference between the results. The result set contains all rows returned from the first query expression except those rows that are also returned from the second query expression. Syntax:- SELECT [TableName1].[ColumnName1] FROM TableName1 EXCEPT SELECT [TableName2].[ColumnName2] FROM TableName2
MERGE Statement with SQL Server 2008

MERGE Statement with SQL Server 2008

MERGE is a new feature that provides an efficient way to perform multiple DML operations. In previous versions of SQL Server, we had to write separate statements to INSERT, UPDATE, or DELETE data based on certain conditions, but now, using MERGE statement we can include the logic of such data modifications in one statement that even checks when the data is matched then just update it and when unmatched then insert it. One of the most important advantage of MERGE statement is all the data is read and processed only once. In previous versions three different statement has to be written to process three different activity (INSERT, UPDATE or DELETE), however using MERGE statement all update activity can be done inone pass of database table. This is quite an improvement in performance of database query
Like Operator Examples in SQL

Like Operator Examples in SQL

Syntax of LIKE Operator : match_expression [ NOT ] LIKE pattern [ ESCAPE escape_character ] match_expression is valid expression of character string data type. Pattern is the pattern to search for in match_expression, escape_character is valid SQL Server expression of any of the data types of the character string data type category. escape_character has no default and must consist of only one character. Return type of like operator is Boolean. LIKE returns TRUE If the match_expression matches the specified pattern. Examples of LIKE Operator:
If Exists and Not Exists in SQL Server

If Exists and Not Exists in SQL Server

Introduced with the keyword EXISTS, the subquery functions as an existence test. The WHERE clause of the outer query tests whether the rows that are returned by the subquery exist. subquery introduced with EXISTS has the following syntax: IF EXISTS ( SELECT *FROM ajay WHERE empid = 12 ) BEGIN print 'Valid Employee' END
Example of SQL SubQuery

Example of SQL SubQuery

Syntax - Subquery SELECT Statement WHERE ColumnName [Comparison Operator] (SELECT Statement / Values) Results of one Sql query or Sql statement as the input for another Select query, Insert Into query, Insert From query,Update query and Delete query. You also can use the result of Subquery as a search condition for using in the IN( ) function or EXISTS operator. Comparison Operator such as =, >, < , >=, <=, LIKE, IN
Example of WHILE Loop With CONTINUE and BREAK Keywords in SQL

Example of WHILE Loop With CONTINUE and BREAK Keywords in SQL

SQL While sets a condition for the repeated execution of an SQL statement or statement block. The SQL statements are executed repeatedly as long as the specified condition is return TRUE. The WHILE loop can be controlled from inside the loop with the CONTINUE,BREAK and GOTO keywords. BREAK statement will exit you from the currently processing WHILE loop. GOTO statement will break out of all WHILE loops, no matter how many nested WHILE statements. CONTINUE statement will skips executing the rest of the statements between the CONTINUE statement and the END statement of the current loop and starts executing at the first line of the current WHILE loop.
Import CSV File Into SQL Server Using Bulk Insert in SQLServer

Import CSV File Into SQL Server Using Bulk Insert in SQLServer

BULK INSERT Imports a data file into a database table or view in a user-specified format in SQL Server 2008 R2. Use this statement to efficiently transfer data between SQL Server and heterogeneous data sources. Arguments : database_name Is the database name in which the specified table or view resides. If not specified, this is the current database. schema_name Is the name of the table or view schema. schema_name is optional if the default schema for the user performing the bulk-import operation is schema of the specified table or view. table_name