9/19/2007

Difference between vb.net and c#

There are so many differences between vb.net and c# which are given below-Here I mentioned the some important differences between vb.net and c#.


1. C# provides operator overloading and vb.net does not provide it.
2. C# supports unsigned integer and vb.net does not.
3. C# does not support optional argument and vb.net supports it.
4. C# runs slightly faster than vb.net.
5. C# inforces strict type casting and vb.net does not enforce it.
6. Event declaration is easier in vb.net than c#.
7. vb.net is flexible of working with arrays which can be resized using Redim statement and c# does not support Redim statement.
8. vb.net is not case sensitive and c# is case sensitive.

The best sites to know the difference between vb.net and c#.net are

1) http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html

2) http://www.codeproject.com/dotnet/vbnet_c__difference.asp

sessions,querystring,application and viewstate

How to pass values between pages in asp.net?

There are several methods to pass values from one page to another page. Described below are few methods to pass values between pages:

1)querystring

2)context

3)session

4)application

5)view state


QueryString

The QueryString collection is used to retrieve the variable values in the HTTP query string.. See the code below to see how QueryString functionality works.

The limit for the query string is 255 chars

//Code in home.aspx
String sString;
sString = Server.UrlEncode("string in home.aspx");
Response.Redirect("DestinationPage.aspx?Value=" & sString);

//Code in DestinationPage.aspx reads the QueryString
String sString;
sString = Request.QueryString("Value");
Response.Write("Your name is " & sString);


Context - The context object is used to send values between pages. Its similar to the session object, the difference being that, the Context object goes out of scope when the page is sent to a browser. Example code below shows how to use Context object.

‘Home.aspx stores value in context before sending it
Context.Items("MyData") = "beklo.com/rameshgoudd";
Server.Transfer("DestinationPage.aspx");

\\\'DestinationPage.aspx retrieves the value from home.aspx's context
String sString;
sString = Context.Items("MyDate").ToString;
Response.Write("The data is as follows: " & sString);

Session –When ever a client makes a request to the server it allocates a block of memory unique to the cient.

Session is stored in the server.

The session object is used to persist data across a user session during the user's visit to a website. It is almost same as the Context object. When we use Response.Redirect, it causes the Context object to go away, so rather the Session object is used in such a scenario. Session object uses more of server memory than a context object. Example code below shows how to use Session object.

‘home.aspx stores value in session before sending it
Session.Items("MyData") = "beklo.com/rameshgoudd";
Response.Redirect("DestinationPage.aspx");

In the page load event declare like this


\\\'DestinationPage.aspx retrieves the value from InitialPage.aspx's session
String sString;
sString = Session.Items("MyDate").ToString;
Response.Write("The data is as follows: " & sString);

Application:

1. ASP.NET Framework applications consist of everything under one virtual directory of the Web server.

2. You create an ASP.NET Framework application by adding files to a virtual directory on the Web server.

3. The lifetime of an ASP.NET Framework application is marked by Application_Start and Application_End events.

4. Access to application-scope objects must be safe for multithreaded access.

Synatax of application:in the home.aspx

Application(“username”)=txtUsername.Text;

In the welcome.aspx calling that application

String s=application(“username”);

Sql Joins with examples

joins:

1)These are used to retrieve the data from more than one table.

2)To retrieve the data from more than one table the datatypes of fields which related to different tables need not be same while using the joins

Types of joins:

1):Inner Join

2):Cross Join

3)OuterJoin

a)Left Outer Join

b)Right Outer Join

c)Full Outer Join

4)Natural Join

5)Equi Join

Examples and Description:

1:Emp

EmployeeID EmployeeName
1 Ramesh
2 Sukumar
3 Ravi
4 Kalyani

2.Products:

ProductID EmployeeID Productname
1 1 2 Pen
12 3 Pencil
1 2 3 Eraser
1 3 6 Book

1):Inner Join:This join returns all the rows from the both the tables where there is a match.The result set consists of only matched rows.

Syntax:

select E. Employeeid,E.EmployeeName,P.ProductName from Employees E inner join Products on E.EmployeeID=P.EmployeeID

Result:

1) EmployeeID EmployeeName Productname
2 Sukumar Pen
3 Ravi Pencil
3 Ravi Eraser

2)Cross Join:Cross join is nothing but retrieving the data from more than one table with out using the condition.

Here two cases are there:

a)select E.EmployeeID,E.EmployeeName,P.Productname from Employees E,Products P

Note:(here we are using the cross join defaultly.Means we have not mentioned the any condition here.)

b)select E.EmployeeID,E.EmployeeName,P.Productname from Employees E cross join Products P

Note:this is the syantax of cross join..both queries(a &b)returns the same result) only the difference is Synatx but the o/p is same.

3)Outer Join:In outer join the resulting table may have empty columns.

a)Left Outer Join:Here left means first table.it reurns all the rows from the first table even though it does not have the matchs in Second table.But it returns only the matched rows from the second table.

Syntax:

select E. Employeeid,E.EmployeeName,P.ProductName from Employees E left join Products on E.EmployeeID=P.EmployeeID

Result:

1) EmployeeID EmployeeName Productname
2 Sukumar Pen
3 Ravi Pencil
3 Ravi Eraser

1 Ramesh null

4 Kalyani null

a)Right Outer Join:Here Right means Second table.it returns all the rows from the second table even though it does not have the matchs in First table.But it returns only the matched rows from the First table.

Syntax:

select E. Employeeid,E.EmployeeName,P.ProductName from Employees E right join Products on E.EmployeeID=P.EmployeeID

Result:

1) EmployeeID EmployeeName Productname
2 Sukumar Pen
3 Ravi Pencil
3 Ravi Eraser

6 null Book

5)Natural JOIN:it eliminates the duplicate values from the output.

6)Equi JOIN:An inner join is called equi-join when all the columns are selected with a *, or natural join otherwise