Chitika

Friday, December 14, 2012

Open Specific Version of Visual Studio from Run Command Prompt

In my previous article i have show you how to open visual studio from Run command prompt.
When you type devenv it will open the latest version of visual studio until you change the registry entries.

To open specific version you have to follow the below steps

  1. Press windows + r it is open run window and then write "regedit" which is open your PC registry.
  2. Then go to HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> Windows -> Currentversion -> App Paths -> devenv.exe
  3. Click on devenv.exe and change the value of default.
When you open default if visual studio 2010 is installed, it has value like 
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
To open visual studio 2008 change it to 
 C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe
To open visual studio 2005 change it to 
 C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe
You need to change the value to your other installation, maybe 
After completed above steps, when you run devenv command it is open the version you specified. 

While changing the entry if you get error saying "can't edit" it means that you don't have permission to change, ask your administrator to change it.


Happy Programming...

Start Visual Studio From Run Command Prompt

This is the short cut to open the visual studio 
Open Run Command Prompt(Start->Programs->Run or Windows Logo + R) and type the text given below.

 devenv : Opens Visual Studio IDE With Splash Screen.
 devenv /nosplash : Opens
Visual Studio IDE Without Splash Screen.
 

If using Visual web developer Express Edition,

 type vwdexpress 

This helps me a lot in starting
Visual Studio IDE. Hope it might help you all.
 

Wednesday, November 21, 2012

Read XML data by attribute in C#


How to create XML document programmatically which i have shown in my previous XML article.
In this example i am going to show you, how to read data from XML document based on the value in c#. Use method XmlNode.Selec­tNodes to get list of nodes selected by the XPath expression. 
Check the  XML file.

<Products>
    <Product Category="0">LG DVD Writer</Name>
    <Product Category="1">I Ball Camera</Name>
    <Product Category="0">LG Monitor</Name>
    <Product Category="1">Creative Speakers</Name>
    <Product Category="0">Intel Mother Board</Name>
    <Product Category="1">Transcend Ram</Name>
    <Product Category="0">HCL Monitor</Name>
    <Product Category="1">Dell Laptop</Name>
    <Product Category="0">Sony DVD Writer</Name>
</Products>


To get all product nodes use XPath expression /Products/Product
To get only 1 category (to select all nodes with specific XML attribute) use XPath expression /Products/Product [@ Category ='1'].
[C#]

XmlDocument xml = new XmlDocument();
xml.LoadXml(str);  // suppose that str string contains "<Names>...</Names>"

XmlNodeList xnList = xml.SelectNodes("/Products/Product[@category='1']");
foreach (XmlNode xn in xnList)
{
  Console.WriteLine(xn.InnerText);
}

The output is:
I Ball Camera
Creative Speakers
Transcend Ram
Dell Laptop

Tuesday, November 20, 2012

Display Yes or No Instead of True or False in asp.net

In asp.net when we are working with there are many places where we get Boolean values which we need to show them for the user in user preferred format. 
Usually we will get this situation when binding  data control  with data bound templates.
For example if we have status of the customer .
To show the customer status to the user in grid we write below statement generally.
<ItemTemplate><%#Eval("Status")%></ItemTemplate>

The output for the above statement will be shown either True/ False based on the status.
But what the user expecting is Yes / No  or Active / In-Active it can be any thing which they prefer to use.
To accomplish this the above statement has to be updated as below,

<ItemTemplate><%#Eval("Status" ? "Yes": "No"%></ItemTemplate>

Based on the user preference we can write anything in place of Yes and No, as

<ItemTemplate><%#Eval("Status" ? "Active": "In-Active"%></ItemTemplate>

Sunday, November 18, 2012

ViewState Security in Asp.net

View state is one of the client side state mechanism. While developing web applications we use view state to maintain state. View state data stores at client side in hidden field. If data stored at client side then it can be hacked easily . 
If we look at view state which is available in hidden field it will be in encrypted format, which is nothing but a Base64 encoded string.
<div class="aspNetHidden"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1MmRk" /> </div>
The above string can be encrypted easily. There are many tools which will encrypt the above string.
Then how to make the view state secure?
You can make sure that the ViewState information is tamper-proof by using “hash codes”. You can do this by adding EnableViewStateMAC=true in your page directive. MAC stands for “Message Authentication Code”.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="AspnetSamples._Default" EnableViewStateMac="true" %>

When we use EnableViewStateMac="True", during ViewState save, ASP.NET internally uses a hash code. This hash code is a cryptographically strong checksum. This is added with the ViewState content and stored in a hidden filed. During postback, the check-sum data is verified again by ASP.NET. If there is a mismatch, the postback will be rejected.
You can see the view state which is encrypted and tamper proof ,
<div class="aspNetHidden"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1MmRkUkrfk7WraO3oDkbzEdzP7B3oVWpynylAgMi0Xne7Pjg=" /> </div>
Conclusion: In asp.net viewstate security is maintained by using EnableViewStateMAC=true property 

Friday, November 16, 2012

Data controls in asp.net


In asp.net we have 4 major  data controls those are
  1. Repeater
  2. ListView
  3. DataList and
  4. GridView

Repeater: 

          Repeater usually works faster because of DataReader class, which is used for read only access. DataReader is faster than DataSet or DataTable classes commonly used with GridView. It doesn't provide paging and sorting of records.

ListView:

           ListView control is newest data presentation control, introduced in ASP.NET 3.5. 
           Now, there is new ListView control which tries to provide best from both sides: speed and flexibility in design, and also a lot of features like paging, updating or deleting of records etc.

DataList:

           DataList has RepeatDirection, RepeatColumns and RepeatLayout properties, which are unique for DataList control. These properties are useful when you need to create presentation with more than one record per row.

GridView:

          GridView displays data in form of grid. Rows and columns are represented as HTML table. This is very useful if you need grid-like presentation. If you need to present data in table layout, then GridView requires a minimum of effort. In same time, if you want more customizable flow layout, GridView is not best option. Common problem when using GridView control could be large ViewState which makes page loads slower and requires more bandwidth. 

Conclusion: When we consider performance the order of these controls would be Repeater, ListView, DataList, and GridView.

Wednesday, November 7, 2012

C# Versions and features



The following diagram shows the list of most important features provided in the specific release up to c# 5.0.


Saturday, October 27, 2012

A Leader Should Know How to Manage Failure


When i surfing the net i have gone through  one of the nice post i really impressed  that i am posting here.

Former President of India APJ Abdul Kalam at Wharton India Economic forum , Philadelphia, United States March 22,2008)

Question: Could you give an example, from your own experience, of how leaders should manage failure?

Kalam:   Let me tell you about my experience. In 1973 I became the project director of India's satellite launch vehicle program, commonly called the SLV-3. Our goal was to put India's "Rohini" satellite into orbit by 1980. I was given funds and human resources -- but was told clearly that by 1980 we had to launch the satellite into space. Thousands of people worked together in scientific and technical teams towards that goal.

By 1979 -- I think the month was August -- we thought we were ready. As the project director, I went to the control center for the launch. At four minutes before the satellite launch, the computer began to go through the checklist of items that needed to be checked. One minute later, the computer program put the launch on hold; the display showed that some control components were not in order. My experts -- I had four or five of them with me -- told me not to worry; they had done their calculations and there was enough reserve fuel. So I bypassed the computer, switched to manual mode, and launched the rocket. In the first stage, everything worked fine. In the second stage, a problem developed. Instead of the satellite going into orbit, the whole rocket system plunged into the Bay of Bengal. It was a big failure.

That day, the chairman of the Indian Space Research Organization, Prof. Satish Dhawan, had called a press conference. The launch was at 7:00 am, and the press conference -- where journalists from around the world were present -- was at 7:45 am at ISRO's satellite launch range in Sriharikota [in Andhra Pradesh in southern India]. Prof. Dhawan, the leader of the organization, conducted the press conference himself. He took responsibility for the failure -- he said that the team had worked very hard, but that it needed more technological support. He assured the media that in another year, the team would definitely succeed. Now, I was the project director, and it was my failure, but instead, he took responsibility for the failure as chairman of the organization.

The next year, in July 1980, we tried again to launch the satellite -- and this time we succeeded. The whole nation was jubilant. Again, there was a press conference. Prof. Dhawan called me aside and told me, "You conduct the press conference today."

I learned a very important lesson that day. When failure occurred, the leader of the organization owned that failure. When success came, he gave it to his team. The best management lesson I have learned did not come to me from reading a book; it came from that experience….

Abstract Class vs Interface


Basically abstract class is an abstract view of any real word entity and interface is more abstract one.
One of the most frequent question in an interview for a Junior/Graduate Developer role is ‘What is the difference between Abstract class and Interface? I have to admit that (as a Graduate).
I thought my intrepidness or whatever that skill I thought I had was far more important than being able to answer the difference between abstract and interface.

                   Abstract Class
Interface
An abstract class can have non-abstract Methods(concrete methods)
In Interface all the methods have to be abstract.
 can declare or use any variables
interface is not allowed to declare variables
In abstract class you can provide default behavior of a function, so that even if child class does not provide its own behavior, you do have a default behavior to work with. Eg. Abstract classes of framework, even if you don’t provide your own behavior, they have a default behavior
You cannot provide a default behavior in interfaces. Interfaces only allow you to provide signature of the method.

You can provide access modifiers to methods in abstract classes.
You cannot provide access modifiers methods in Interfaces.

the aim: making sure something is *eventually* implemented.
the aim: making sure something is interchangeable.
abstract class can have constructor declaration
interface cannot do so
abstract Class is allowed to have all access modifiers for all of its member declaration
Interface we can not declare any access modifier (including public) as all the members of interface are implicitly public.  
we cannot achieve multiple inheritance
Using an Interface we can achieve multiple inheritance.
Can be static , virtual ,abstract or sealed
Interface member cannot be defined using the keyword static, virtual, abstract or sealed
IS-A relationship
CAN-DO relationship.
e.g. Student IS A Person, Employee IS A Person.
e.g. Student CAN enrol, Student CAN submit assignment.
Ex: abstract class AbstractClass
{
    public AbstractClass ()
    {
    }
    int count = 0;
    int Max = 100;
    public abstract void getClassName();
}
Ex:

interface MyInteface
{
    void Method1();
    string Method2();
}


Saturday, October 20, 2012

Java Script Mouse Over Effect

This is the sample i am going to show you how to write on mouse effect using java script.Put your cursor here.


For the above sample you can check the code below.
The below code is used to show the alert on mouse over effect in java script
<table style="width: 40%px;"><tbody>
<tr>
<td align="right"><a href="http://draft.blogger.com/blogger.g?blogID=936809412703174765" onmouseover="alert(You are reading my blog.')">
This is the sample i am going to show you how to write on mouse effect using java script.Put your cursor here.</a></td></tr>
</tbody></table>

Put cursor on below image.


You can find all articles related to java script here


SQL SERVER Commands


This is the continuation of my articles on sql server.
In my previous article i have explained about database & table creation and data types in sql
DML
DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.
SELECT – Retrieves data from a table
INSERT -  Inserts data into a table
UPDATE – Updates existing data into a table
DELETE – Deletes all records from a table
DDL
DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.
CREATE – Creates objects in the database
ALTER – Alters objects of the database
DROP – Deletes objects of the database
TRUNCATE – Deletes all records from a table and resets table identity to initial value.
DCL
DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.
GRANT – Gives user’s access privileges to database
REVOKE – Withdraws user’s access privileges to database given with the GRANT command
TCL
TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.
COMMIT – Saves work done in transactions
ROLLBACK – Restores database to original state since the last COMMIT command in transactions
SAVE TRANSACTION – Sets a savepoint within a transaction
My previous article on sql server about database & table creation and data types in sql

Friday, October 19, 2012

Data base and table creation in sql server


In my previous article i have given introduction to sql server data types now its time for creating database and table.
Database:

SQL Server manages the objects in a container known as Database, where we can have multiple databases present in it, each database when created creates 2 files internally those or .mdf and .ldf file.

Syntax for creating a database:
            -CREATE DATABASE <db_name>
           
-Database names must be unique within an instance of SQL Server.
-Any Object name in sqlserver can be of 1 through 128 characters

Tables:

-It is the object, which will store the information in the database in the form of rows and columns.

Syntax for creating a Table:
            -CREATE TABLE <table_name>(
             column_name1 <dtype> [width],
             column_name1 <dtype> [width],
             ………………….
             column_namen <dtype> [width])

-Table names must be unique within the database.
-Column names must be unique within the table.
-Every table can have maximum of 1024 and minimum of 1 column.

            -CREATE TABLE Bank(Custid int, Cname varchar(50), Bal decimal(7,2))
In the next article i will explain about commands in sql server.

Thursday, October 18, 2012

Data types in sql server

Data Types in sql server 
In a Database, each column, local variable, expression, and parameter has a related data type. A data type is an attribute that specifies the type of data that the object can hold: integer data, character data, monetary data, data and time data, binary strings, and so on.

Integer Types: To hold the Integer values it provides with tinyint, smallint, int and bigint data types with sizes 1, 2, 4 and 8 bytes respectively.

Boolean Type: To hold the Boolean values it provides with bit data type that can take a value of 1, 0, or NULL.
Note: The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1 and FALSE is converted to 0.

Decimal Types: To hold the decimal values it provides with the following types:

            -decimal[ (p[ , s] )] and numeric[ (p[ , s] )]

p (precision)
The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.
s (scale)
The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. Scale can be specified only if precision is specified. The default scale is 0.

Storage sizes of Decimal and Numeric types vary, based on the precision.

Precision
Storage bytes
1 – 9
5
10-19
9
20-28
13
29-38
17

Note: numeric is functionally equivalent to decimal.
 
-float [ ( n ) ] and real
-Approximate-number data types for use with floating point numeric data. Floating point data is approximate; therefore, not all values in the data type range can be represented exactly. Where n is the number of bits that are used to store the mantissa of the float number in scientific notation and, therefore, dictates the precision and storage size. If n is specified, it must be a value between 1 and 53. The default value of n is 53.

n value
Precision
Storage size
1-24
7 digits
4 bytes
25-53
15 digits
8 bytes

Monetary or Currency Types: To hold the Currency values it provides with the following types which takes a scale of 4 by default:
           
money
-922,337,203,685,477.5808 to 922,337,203,685,477.5807
8 bytes
smallmoney
- 214,748.3648 to 214,748.3647
4 bytes

Date and Time Values: To hold the Date and Time values of a day it provides with the following types:
           
Data type
Range
Accuracy
datetime
January 1, 1753, through December 31, 9999
3.33 milliseconds
smalldatetime
January 1, 1900, through June 6, 2079
1 minute
Values with the datetime data type are stored internally by the Microsoft SQL Server 2005 Database Engine as two 4-byte integers. The first 4 bytes store the number of days before or after the base date: January 1, 1900. The base date is the system reference date. The other 4 bytes store the time of day represented as the number of milliseconds after midnight.
The smalldatetime data type stores dates and times of day with less precision than datetime. The Database Engine stores smalldatetime values as two 2-byte integers. The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes since midnight.
String Values: To hold the string values it provides with the following types:
char [ ( n ) ]
Fixed-length, non-Unicode character data with a length of n bytes. n must be a value from 1 through 8,000. The storage size is n bytes.
varchar [ ( n | max ) ]
Variable-length, non-Unicode character data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of data entered + 2 bytes.
text
It was equal to varchar(max) this data type will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work use varchar(max) instead.
Unicode Data types for storing Multilingual Characters are nchar, nvarchar and ntext where n stands for national.
nchar [ ( n ) ]
Fixed-length Unicode character data of n characters. n must be a value from 1 through 4,000. The storage size is two times n bytes.
nvarchar [ ( n | max ) ]
Variable-length Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes.
ntext
It was equal to nvarchar(max) this data type will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work use nvarchar(max) instead.

Binary Values: To hold the binary values likes images, audio clips and video clips we use the following types.

binary [ ( n ) ]
Fixed-length binary data with a length of n bytes, where n is a value from 1 through 8,000. The storage size is n bytes.
varbinary [ ( n | max) ]
Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes.
Image
It was equal to varbinary(max) this data type will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work use varbinary(max) instead.
  • Use char, nchar, binary when the sizes of the column data entries are consistent.
  • Use varchar, nvarchar, varbinary when the sizes of the column data entries vary considerably.
  • Use varchar(max), nvarchar(max), varbinary(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.
Other Types: Apart from the above it provides some additional types like -
timestamp: Is a data type that exposes automatically generated, unique binary numbers within a database. The storage size is 8 bytes. You can use the timestamp column of a row to easily determine whether any value in the row has changed since the last time it was read. If any change is made to the row, the timestamp value is updated. If no change is made to the row, the timestamp value is the same as when it was previously read.
Uniqueidentifier: Is a 16-byte GUID which is initialized by using the newid() function or converting a string constant in the form of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx which is used to guarantee that rows are uniquely identified across multiple copies of the table.

Xml: Is the data type that stores XML data. You can store xml instances in a column, or a variable of xml type. The stored representation of xml data type instances cannot exceed 2 gigabytes (GB) in size. 

In the next articles i will discuss about creating database and table then commands in sql