Monday, June 27, 2011

How to find the files from all the sub folders in C#.Net?

using System.IO;

string[] filePaths = Directory.GetFiles(@"C:\Kanna\", "*.jpg", SearchOption.AllDirectories);

How to round the decimal values in C#.Net?

string text = "19500.36";
decimal value;
if (decimal.TryParse(text, out value))
{
value = Math.Round(value);
text = value.ToString();
// Do something with the new text value
}
else
{
// Tell the user their input is invalid
}

Monday, February 28, 2011

How to find Gridview row?

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
ImageButton btn = (ImageButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;

string value = GridView1.Rows[row.RowIndex].Cells[0].Text;
Session["value"] = value;
}

Wednesday, February 16, 2011

What is C# Guid.empty() equivalent in Sql Server?

C#
--
Guid.empty()

SQL
---
cast(cast(0 as binary) as uniqueidentifier)

Sunday, September 19, 2010

How to make CD Autorun?

For msi file. save as autorun.inf
=================================

[autorun]
ShellExecute=MyInstaller-1.0.0.msi
label=My CD Label
icon=MyIcon.ico

for exe file. save as autorun.inf
=================================

[autorun]
open=Test.exe
label=My CD Label
icon=MyIcon.ico

Often the program you want to run will not be located in the root directory of the CD. If that is the case you must include the path in autorun.inf:

[autorun]
open=folder1\folder1A\myfile.exe
icon=myicon.ico

Sometimes you may also need to pass an argument to the program to be auto played:

[autorun]
open=myprogram.exe /argument
icon=myicon.ico

To open the html file ‘index.htm’ would require:
===============================================

[autorun]
ShellExecute=index.htm
icon=index.htm

However, since some older versions of Windows do not support ‘ShellExecute’ a less elegant alternative would be:

[autorun]
open=command /c start index.htm
icon=index.htm

Thursday, September 16, 2010

What is difference between DELETE & TRUNCATE commands?

Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command.


TRUNCATE
TRUNCATE is faster and uses fewer system and transaction log resources than DELETE.
TRUNCATE removes the data by deallocating the data pages used to store the table’s data, and only the page deallocations are recorded in the transaction log.
TRUNCATE removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column.
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint.
It cannot activate a trigger.
TRUNCATE can not be Rolled back using logs.
TRUNCATE is DDL Command.
TRUNCATE Resets identity of the table.
DELETE
DELETE removes rows one at a time and records an entry in the transaction log for each deleted row.If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.
DELETE Can be used with or without a WHERE clause
DELETE Activates Triggers.
DELETE Can be Rolled back using logs.
DELETE is DML Command.
DELETE does not reset identity of the table.

What is normalization and their different forms?

Database normalization is a data design and organization process applied to data structures based on rules that help build relational databases. In relational database design, the process of organizing data to minimize redundancy. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships.


TypesDescription
1NFEliminate Repeating Groups Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.
2NFEliminate Redundant Data If an attribute depends on only part of a multi-valued key, remove it to a separate table.
3NFEliminate Columns Not Dependent On Key If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key
BCNFBoyce-Codd Normal Form If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.
4NFIsolate Independent Multiple Relationships No table may contain two or more 1:n or n:m relationships that are not directly related.
5NFIsolate Semantically Related Multiple Relationships There may be practical constrains on information that justify separating logically related many-to-many relationships.
ONFOptimal Normal Form A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.
DKNFDomain-Key Normal Form A model free from all modification anomalies.
Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database.

What is View?

A simple view can be thought of as a subset of a table. It can be used for retrieving data, as well as updating or deleting rows. Rows updated or deleted in the view are updated or deleted in the table the view was created with. It should also be noted that as data in the original table changes, so does data in the view, as views are the way to look at part of the original table. The results of using a view are not permanently stored in the database. The data accessed through a view is actually constructed using standard T-SQL select command and can come from one to many different base tables or even other views.

What is Index?

An index is a physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries. Effective indexes are one of the best ways to improve performance in a database application. A table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance.

Clustered indexes define the physical sorting of a database table’s rows in the storage media. For this reason, each database table may have only one clustered index.
Non-clustered indexes are created outside of the database table and contain a sorted list of references to the table itself.

Tuesday, September 14, 2010

ASP.Net Page Life Cycle

The events occur in the following sequence. Its best to turn on tracing(<% @Page Trace=”true”%>) and track the flow of events
PreInit This event represents the entry point of the page life cycle. If you need to change the Master page or theme programmatically, then this would be the event to do so. Dynamic controls are created in this event.
Init Each control in the control collection is initialized.
Init Complete* Page is initialized and the process is completed.
PreLoad* This event is called before the loading of the page is completed.
Load This event is raised for the Page and then all child controls. The controls properties and view state can be accessed at this stage. This event indicates that the controls have been fully loaded.
LoadComplete* This event signals indicates that the page has been loaded in the memory. It also marks the beginning of the rendering stage.
PreRender If you need to make any final updates to the contents of the controls or the page, then use this event. It first fires for the page and then for all the controls.
PreRenderComplete*Is called to explicitly state that the PreRender phase is completed.
SaveStateComplete*In this event, the current state of the control is completely saved to the ViewState.
UnloadThis event is typically used for closing files and database connections. At times, it is also used for logging some wrap-up tasks.
The events marked with * have been introduced in ASP.NET 2.0.
 
Feedback Form