Wednesday 26 September 2012

What are differences between system.stringbuilder and system.string?


1.)system.string is immutable but system.stringBuilder is mutable.
Immutable means once we created we cannot modified.    Suppose we want give new value to old value simply it discarded the old value and it will create new instance in memory to hold the new value.
2.)append keyword is used in string builder but not in system.string.

What is difference between Array list and hash table?


1.)Hash table store data as a name ,value pair while in array only value is store.
2.)To access value from Hash table ,you hve to pass name while in array ,to access value, you have to pass index number.
3.)You can store different data type in Hash table like int, string but in array you can store only similar type of data.

What are differences between Abstract and Interface?

Hi friends ,here i have explained "What are differences between Abstract and Interface".


Abstract Class:
->abstract  class provides a set of rules to implement next class.
->Abstract method does not contain any definition.
->In abstract all method are default.
->If a class contains at least one abstract method then it must be declared as an “Abstract class”.
->Abstract  classes cannot be instantiated i.e we cannot create object, but reference  can be created.
->If  a class contains all functions without  body then it is called as “Fully Abstract Class” .i.e Interface.

Interface:
->If a class contain all abstract methods then that class is known as “Interface”.
->Interface support multiple inheritance.
->In interface all method are public  by default.
->Interfaces are implementable.
->Interfaces cannot be instantiated , but a reference can be created.

What is the difference between stored procedure and function?



Hi friend , here i have explained "What  is the difference between stored procedure and function "
1.)Stored procedure can return  zero or more  means 0 or n values where as function can return only one value which is mandatory.
2.) Stored procedure have input , output parameters for it  whereas function can have only input parameters.
3.)Stored procedure allows to select as well as DML statement in it whereas function allows only select statement in it.
4.)Stored procedure can called a function whereas function can not called a stored procedure.
5.) Exception can be handled by try –catch block in a stored procedure but try-catch  block cannot be used in a function.
6.)We can go for transaction management in stored procedure but we cannot go in function.

What is an application object?



Hi friend , here i have explained about Application object.

Introduction:

Application object is used to store the information and access variables from any page in the application. Application object is same as the Session  object but only difference is that session object is used only for particular user.Apllication object  is same for all users once application object is created that application is used through out  all the pages in application (like database connection) and we change the application object  one  place those will changes in all the pages.
You can create the application object in Global.asax file and access those variable in all the pages. 
Add  the following code in Global.asax file :
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["UserID"] = "SureshDasari";
}
</script>
After this write the following code in aspx page:
<html> 
<head> 
<title>Application Object Sample</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<asp:Label id="lblText" runat="server"></asp:Label> 
</form> 
</body> 
</html> 

After that write the following code in .cs file:
public void Page_Load(object sender, EventArgs e)
{
this.lblText.Text =  "UserName: " + Application["UserID"] + "<br>";
}

Tuesday 25 September 2012

What are the difference between ExecuteNonQuery , ExecuteReader and ExecuteScaler in ADO.NET

Hi friend,in this article i have explained what is the basic deifference between  ExecuteNonQuery , ExecuteReader and ExecuteScaler in ADO.NET.

ExecuteNonQuery:

ExecuteNonQuery method will return number of rows effected by INSERT,DELETEor UPDATE operations.ExecuteNonQuery method will be used only for insert,update,delete,and set staements;

ExecuteScaler :

ExecuteScalar method will return single row single column value i.e single value, on execution of sql query or stored procedure using command object.It is very fast to retrieve single values from database.

ExecuteReader :

ExecuteReader will be used to return the set of rows on execution of sql query or stored procedure using command object.This is used only forward retrieval of records and it is used to the table value from the first to last.

What is stored procedure ? What are the advantages using stored procedure in sql server

Hi friend, here i have explained about store procedure in sql server.

What is stored procedure:

Stored procedure is a group of sql statements that has been created and stored in the database.It is a pre-compiled sql query.It will accept input parameters so that a procedure can be used over the network by several clients using different input data. It reduce network traffic and increase the performence. if we modify the stored procedure all the clients will get the updated stored procedure.

sample of creating stored procedure:

create procedure procedure_name
(
@column_name1 datatype,
@column_name2 datatype,
@column_name3 datatype,
@column_name4 datatype
)
as begin
select * from table_name;
end;

Advantages of stored procedure:

1)stored procedure allows moduler programming.
You can create the procedure once,store in the database ,and call it many number of time in your program.

2)stored procedure allows faster execution.
  because it is precompiled sql query.

3)It reduces the network traffic.

4)Stored procedure provide the better security to your data.

There are three types of stored procedure:
a)system  stored procedure
b)user defined stored procedure
c)Extened stored procdure

How to find highest salary from different department

Hi friends,In this article i have explained how to find max salary from different department.
First create a table in database .
Enter some data in the table with different department .
Example:

create table m_salary(empid varchar(50),empname varchar(50),salary varchar(50),deptid varchar(50))
Enter some values in the table.

Sql query :

select deptid , MAX(salary) as sal  from m_salary  group by deptid ;

Run this query and I hope this will help you.

Difference between char,varchar and nvarchar in sql server

Hi friends,In this article i have explained what is the difference between char , varchar and  nvarchar in sql server.

char Data Type:

char datatype is used to store fixed length of character.For example if we declared char(50) it will allocate memory for character 50. once we declare char(50) and insert only 10 character then it only use 10 character of memory and other 40 character of memory will be wasted.

varchar datatype:

Varchar means variable character .It will allocate the memory based on number of character inserted. Suppose that if we have declare varchar(50) it allocate 0 memory of character  at the time of declaration.
Once we declare varchar(50) and insert only 10 values the it only use 10 character of memory.

nvarchar datatype:

nvarchar datatype same as varchar datatype but only difference nvarchar is used to store unicode characters and  it allows to store multiple lagauges in database.
 

Tuesday 18 September 2012

Arrange the string in ascending and descending order

Hi Friend, I hope you have enjoyed from my previous article .i.e When user enter numeric value ,print out the character values.
Here i will explain how to arrange string in ascending and descending order.
First open visual studio > open new project> click on console application > give the name of the application> click ok.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//user to enter list of username
Console.WriteLine("please enter the name seperated by comma");
//read the user name from console
string username = Console.ReadLine();
// split the string into string array by comma
string[] arrusername = username.Split(',');
// print the name before sorting
Console.WriteLine("Name before sorting");
foreach(string userName in arrusername)
{
Console.WriteLine(userName);
}
// sort the element in ascending order
Array.Sort(arrusername);
// print the element after sorting
Console.WriteLine("string after sorting");
foreach(string userName in arrusername)
{
Console.WriteLine(userName);
}
// sort the element for descending order
Console.WriteLine("-------------------for Descending order");
Array.Reverse(arrusername);
// print the element in descending order
foreach(string userName in arrusername)
{
Console.WriteLine(userName);
}
Console.ReadLine();
}
}
}

I hope you will enjoy with this code.

When user enter numeric value ,print out the character values

Hi friend , this question is generally asked from freshers and sometime from experianced professionals.

The question is when user enter numeric value then it print character value .
Here i have explained how to overcome from this problem.
First open a console application in visual studio and give it some name.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace printcharacter
{
class Program
{
static void Main(string[] args)
{
  Console.WriteLine("please enter  numeric value");
int str = Convert.ToInt32(Console.ReadLine());
Console.WriteLine((char)(str + 64));

Console.ReadLine();
}
}
}

I hope You will enjoy .