Wednesday, 27 July 2011

Monday, 25 July 2011

Threads

Thread th = new Thread(Fill_IgGrid);
th.Priority = ThreadPriority.Normal;
th.IsBackground = true;

th.Start(_List); //object of the parameter (_Generic List)
or
th.Start(); // non of parameter

private void Fill_IgGrid()
{
 //------- Grid bind code
}

Saturday, 23 July 2011

What is the purpose of XML Namespaces?

An XML Namespace is collection of element types and attribute names. It consists of two parts :

1) The first part is the URI used to identify the namespace
2) The second part is the element type or attribute name itself.


The various purpose of XML Namespace are
1. Combine fragments from different documents without any naming conflicts.
2. Write reusable code modules that can be invoked for specific elements and attributes. Universally unique names guarantee that
such modules are invoked only for the correct elements and attributes.
3. Define elements and attributes that can be reused in other schemas or instance documents without fear of name collisions.
 

Friday, 22 July 2011

Can you encrypt view state data of an aspx page?

Yes, you encrypt view state data of an aspx page by setting the page's ViewStateEncryptionMode property to true.

What is the advantage of storing an XML file in the applications App_Data folder?

The contents of the App_Data folder will not be returned in response to direct HTTP requests.

What are the best practices to follow to secure connection strings in an ASP.NET web application?

1. Always store connection strings in the site's Web.config file. Web.config is very secure. Users will not be able to access web.config from the browser.
2. Do not store connection strings as plain text. To help keep the connection to your database server secure, it is recommended that you encrypt connection string information in the configuration file.
3. Never store connection strings in an aspx page.
4. Never set connection strings as declarative properties of the SqlDataSource control or other data source controls.
Why is "Connecting to SQL Server using Integrated Security" considered a best practice?Connecting to SQL Server using integrated security instead of using an explicit user name and password, helps avoid the possibility of the connection string being compromised and your user ID and password being exposed.

StreamReader and StreamWriter classes in .Net

Hi friends,in this post i would like to explain StreamReader & StreamWriter classes in C#.Net.

* StreamReader is used to read data from the file.
* StreamWriter is used to write data into the file.
* Directly we are not write data into the file. First we should write into RAM & then through flush() it will be   written into the file.

StreamReader methods:

1)Read() : Reads single character.
2)ReadLine() : Reads single line.
3)ReadToEnd() : Reads full file.

For Example:

StreamReader str=new StreamReader(file1);
txtBox1.Text=str.ReadToEnd();
str.Close();

StreamWriter methods:

1)Write()
2)WriteLine()

For Example:

StreamWriter stw=new StreamWriter(file1);
stw.Write(txtBox1.Text);
stw.Flush();
stw.Close();

Thursday, 21 July 2011

Type Casting In .Net

* Type casting is the concept of converting one datatype to another datatype.

* C#.Net supports 2 types of type casting:
1)Implicit type casting.
2)Explicit type casting.

* Implicit type casting is under control or CLR.
* Explicit type casting is under control of programmer.

* Converting from Lower data types into Higher data types is called as Implicit type casting.
For Example:
Byte---->Long(Implicit)

* Converting from Higher data types into Lower data types is called as Explicit type casting.
For Example:
long---->int(Explicit)

Thursday, 7 July 2011

Magic table in sql

The tables "INSERTED" and "DELETED" are called magic tables of the SQL Server. 
We can not see these tables in the data base.But we can access these tables from the "TRIGGER".
When we insert the record into the table, the magic table"INSERTED" will be created 
In that table the current inserted row will be available. We can access this record in the 
"TRIGGER".
When we delete the record from the table, the magic table "DELETED" will be created
In that table the current deleted row will be available. We can access this record in the
"TRIGGER".
When we update the record from the table, the both magic table will be created. old values insert in "DELETED" table and new values insert in "INSERTED" table. We can access both record through the "TRIGGER".
Example :
Create the tables :
create table LOGTABLE (UserId nvarchar(100),Message nvarchar(100),Mode nvarchar(50))
create table tblAccountDetail(Acc_id int,Acc_Code nvarchar(100),Acc_Name nvarchar(100))
Create insert trigger
create TRIGGER LogMessage_Insert
ON tblAccountDetail
FOR INSERT
AS
   DECLARE @Code varchar(50)
   DECLARE @NAME varchar(50)
   SELECT @Code= Acc_code,@NAME =Acc_Name  FROM INSERTED
   INSERT INTO LOGTABLE(UserId,Message,Mode) values (@Code,@NAME,'Insert')
GO
create update trigger
create trigger logMessage_Update
on tblAccountDetail
for update
as 
   DECLARE @Code varchar(50)
   DECLARE @NAME varchar(50)
   SELECT @Code= Acc_code,@NAME =Acc_Name  FROM INSERTED
   INSERT INTO LOGTABLE(UserId,Message,Mode) values (@Code,@NAME,'Update New')   
   
   DECLARE @Code1 varchar(50)
   DECLARE @NAME1 varchar(50)
   SELECT @Code1= Acc_code,@NAME1 =Acc_Name  FROM DELETED
   INSERT INTO LOGTABLE(UserId,Message,Mode) values (@Code1,@NAME1,'Update Old')
GO
create delete trigger
CREATE TRIGGER LogMessage_Delete
ON tblAccountDetail
FOR DELETE
AS
   DECLARE @Code varchar(50)
   DECLARE @NAME varchar(50)
   SELECT @Code= Acc_code,@NAME =Acc_Name  FROM DELETED
   INSERT INTO LOGTABLE(UserId,Message,Mode) values (@Code,@NAME,'Delete')
GO
///////////////
insert into tblAccountDetail values(1,'Code-1','Name-1')
in this case trigger will auto fired and insert new row in LOGTABLE table 
select from the magic tables "INSERTED"

Saturday, 2 July 2011

About Yourself

Now I am looking for a challenging internship position in an established company. Basically,
I am an experienced and flexible person can be successful at any kind of works.
"Hardworking", "Task-oriented", "Solution-oriented", "Dependable", "Motivated",
"Independent", "Team player" are all examples of good terms you can use.
There are many more.
I am a self-starter dedicated, hard-working person who works well with other, punctual, detail oriented a team player, great organizational and interpersonal skills.

What is foreign key ?

 A foreign key points to the primary key of another table or A foreign key represent the value of a primary key in a related table. While primary keys must contain unique values, foreign keys may have duplicates.
For instance, if we use student ID as the primary key in a Students table (each student has a unique ID), we could use student ID as a foreign key in a Courses table: as each student may do more than one course, the student ID field in the Courses table (often shortened to Courses.student ID) will hold duplicate values

The purpose of the foreign key is to maintain referential integrity of the data.

What is Primary key?

Primary key is used to uniquely identify a row in a table. A table can have only one primary key. Primary keys don’t allow null values. Primary key will create clustered index by default. It can be defined at the column level or at the table level.
Primary Key can be defined while creating a table with Create Table command or it can be added with the Alter table command.

Primary key defined at the column level:
When we define a primary key at single column then it is called Column-level primary key.
create table tblStudent(studentId int primary key,studentName nvarchar(100), Departmenttid int)

Primary key defined at the table level:
when we define a composition key on two or more than two columns then it is called table-level primary key.

‘OR’
If a primary key is a combination of two or more than two columns then it can only be defined at the table level only.

create table tblStudent(studentId int, studentName nvarchar(100), Departmenttid int , primary key (studentId, DepartmentId))

Adding Primary Key constraint using Alter table command:

Suppose there is no primary key defined for the table tblStudent and we want to add a primary key constraints on the column studentId.

 The query for Adding a primary key with the Alter Table command is as follows:-
Syntax:
Alter Table tablename Add constraint constrainname Primary Key (Columnname)
Example:
Alter Table tblStudent add constraint  pk_StuPrimaryKey  primary key(studentId)

Dropping a primary constraint from a table :

Syntax:
Alter Table tablename Drop constraintname

Example:
alter table tblStudent  drop constraint  pk_ StuPrimaryKey

Advantages:
1. It is a unique key on which all the other candidate keys are functionally dependent.
2. It prevents to enter null data.
3. It prevents to enter duplicate data.
4. It helps to force integrety constraints.

Disadvantage:
On primary key index will be created so during updation of table index need to be adjusted accordingly. this process makes the updation slower

Friday, 1 July 2011

What is Constraints ?

Constraint is a mechanism/Property it is used to prevent the invalid data entry in to the table is called constraint. These constraints ensure the accuracy and reliability of the data into the tables.
Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).

Difference between Function and StoreProcedure ?

1. functions MUST return a value, procedures need not be.
2. sp takes input,output parameters, function takes only input parameters.
3. sp can not be called directly into DML statements , but functions can be called directly into DML statements.
4. Procedure can return zero or n values whereas function can return one value which is mandatory.
5. Functions can be called from procedure whereas procedures cannot be called from function.
6. Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
7. We can go for transaction management in procedure whereas we can't go in function.
8. Function can be used inside the queries but Store procedure never used inside the queries For Example
      Given below:
      select avg(salary) from employee;// allowed here
      avg(): is function
      Select sp(salary) from employee // Not allowed here
      sp(): is stored Procedure
9. Print function can not be called within the function but it can be called within the stored procedure.
10. A stored procedure can return multiple parameters but a function can return only one value.

String.Empty Vs Empty Quotes ?


The difference between string.Empty and "" is very small. String.empty will not create any object while "" will create a new object in the memory for the checking. Hence string.empty is better in memory management.
But do not forget to make a checking for null value if you are also expecting null value in the comparison.

What's the difference between Response.Write() and Response.Output.Write()?


Response.write() is used to display the normal text and Response.output.write() is used to display the formated text.
Response.write - it writes the text stream.
Response.Write("<h1>"+  DateTime.Now.Tostring() + "</h1>");
 
Response.output.write - it writes the HTTP Output Stream. 
Response.Output.Write("<h2>Process running as {0}</h2>",WindowsIdentity.GetCurrent().Name);
As per ASP.NET 3.5, Response.Write has 4 overloads, while Response.Output.Write has 17 overloads.

What is the Static Member ?


When you declare a member variable as static and when the application starts, the compiler creates a copy of that member. This member would be maintained by the compiler while the program is running. If you declare an instance of a class, the static member is not part of the object: the compiler creates and maintains the static member, whether you use it or not, whether you declare a class variable or not.
When a class has a static member variable, you don't need to declare an instance of that class to access the static member variable. When the application starts, the member variable is automatically available and you can access it when necessary. You can access it either to retrieve its value or to modify it.
Variables and methods marked static belong to the class rather than to any particular instance of the class. These can be used without having any instances of that class at all. Only the class is sufficient to invoke a static method or access a static variable. A static variable is shared by all the instances of that class i.e only one copy of the static variable is maintained.

What is the Static Class ?


We can declare a static class. We use static class when there is no data or behavior in the class that depends on object identity. A static class can have only static members. We cannot create instances of a static class using the new keyword. .NET Framework common language runtime (CLR) loads Static classes automatically when the program or namespace containing the class is loaded.

Here are some more features of static class
  • Static classes only contain static members.
  • Static class cannot create any objects
  • Static classes are sealed.  
  • Static class can have only private constructors 
  • Static loads automatically when the CLR loads the namespace of the class.

What is difference between class and structure ?

1. Classes are reference types and structs are value types.
2. A class variable can be assigned null because classes are reference type. But we cannot assign null to a struct variable because structs are value type.
3. When you instantiate a class, it will be allocated on the heap. When you instantiate a struct, it gets created on the stack.
4. Classes support inheritance. But there is no inheritance for structs.
5. Classes are used for complex and large set data. structs are simple to use.
6. Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory.
7. Classes can have explicit parameter less constructors. But structs cannot have this.
8. Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.
9. By default, all of the members of a class are private and, by default, all of the members of a structure are public.
10.  There is no data hiding features comes with structures. Classes do, private, protected and public.
11.  A structure can't be abstract, a class can.
12.  A structure is contain only data member , but class contain data member and member function.
13.  Struct cannot have default constructor but class have default constructor. 
14.  Structs can't have destructors, but classes can have destructors.
   
Note : a struct is a value type, a class is a reference type.  Value types hold their value in memory where they are declared, but reference types hold a reference to an object in memory. If you copy a struct, C# creates a new copy of the object and assigns the copy of the object to a separate struct instance. However, if you copy a class, C# creates a new copy of the reference to the object and assigns the copy of the reference to the separate class instance.