Thursday, 28 July 2011

.Net Interview Question Level 1



Basic Interview Question .Net
Few very basic question you need to keep in mind in interview of asp.net  where database is sql.you should be more curious toward each question to arise few more question from them.i have posted some in below of the post



1) Difference between a primary key and a unique key in SQL? 

primary key doesn't allow duplicate values and does not allow null.
unique key also doesnot allow duplicate values but allows one null value

2) difference between asp and asp.net 

The .NET compliant languages can be used with ASP.NET like C# and VB.NET, where both of them are server-sided languages. With ASP, only VBScript and JavaScript are available as options to be used.  

 

3) What are the new features in ASP.net 3.5 

The most significant improvements in ASP.NET are:

* Integrated Ajax Support
* New Data Controls (ListView and DataPager)
* The LinqDataSource Control

Visual Studio 2008 has also included some features for an improved web application development experience. Here is the list of such improvements:

* Support for LINQ
* IntelliSense for JavaScript and ASP.NET Ajax
* Improved Design time experience

4) Choosing a Web Service or .Net Remoting in projects?

Well Web services uses .Net remoting concepts internally. But the major difference between web service and .net remoting is that “web service” can be consumed by clients who are not .NET platform. While remoting you need the client to be .NET compliant.

Regarding the speed issue ".net Remoting" is faster than “Web Services”. So I think when deciding the architecture side of choosing between “Web services” and “.NET Remoting” keep the cross platform issue and the speed issue in mind. 

 

5) Difference between DataSet and DataReader? 

DataSet is a disconnected architecture, while DataReader has live connection while reading data. If we want to cache data and pass to a different tier DataSet forms the best choice and it has decent XML support.

When application needs to access data from more than one table DataSet forms the best choice.

If we need to move back while reading records, datareader does not support this functionality.

One of the biggest drawbacks of DataSet is speed. As DataSet carry considerable overhead because of relations, multiple tables etc speed is slower than DataReader. Always try to use DataReader wherever possible, as it’s meant specially for speed performance. 

 

6) What is the difference between Hash Table and Arrays?

 1.Array is a collection of same datatype
while

arrays are objects that derive from the base Array class and implement IEnumerable so that array elements can be enumerated with a For-Each loop.

2.Hash table is a colletion of different datatype. 

Hash tables hold a collection of DictionaryEntry objects, where a DictionaryEntry holds the Key along with its value.

7) Difference between C# and C programming Language? 

C# does not usually make use of pointers. You can only increment, or decrement a variable as if it were an actual memory pointer inside a special unsafe block.

You can declare variables anywhere inside a method you want to; they don’t have to be at the beginning of the method.


You don’t have to declare an object before you use it; you can define it just as you need it.

C# has a somewhat different definition of the struct types, and does not support the idea of a union at all.

C# has enumerated types, which allow a series of named values, such as colors or day names, to be assigned sequential numbers, but the syntax is rather different.

C# does not have bit fields: variables that take up less than a byte of storage.

C# does not allow variable length argument lists. You have to define a method for each number and type of argument. However C# allows for the last argument of a function to be a variable parameter array.
 


Few more on above 7 question  you can explore...

1)foreign key?relation with foreign key?

2)MVC?

3).net 4.0 and further

4)WCF basic concept

5)disconnected and connected architecture

6)dictionary

7)c++ 




Sunday, 24 July 2011

Linq to SQL Basics for asp.net

In my section,the basics of LINQ include few steps you can say just 15 steps...my this section is basically for developers who are new to sql and don't know how to implement LINQ in asp.net
OK so here we start!

1)if i am not wrong you know basics of asp.net
2)OK so just create a new project for LINQ
3)if i am not wrong,now you have a default.aspx

4)now right click on your project and in add new item,add LINQ TO SQL CLASS(which will create DataClasses.dbml(which include layout+cs file) don't bother about any thing everything is on the right way
5)Now Look on server explorer in left side of your Visual studio (if not then go to menu bar on head view>>server explorer)
6)now go to the table you want to work with LINQ
7)open the DataClasses.dbml you've just created and Drag your table from server explorer to DataClasses.dbml file(believe,Dragging works here)
8)now DEBUG the DataClasses.dbml file
9)Now from here the actual work starts...look at the DataClasses.designer.cs(under DataClasses.dbml),after debuging the DataClasses.designer.cs includes your table value automatically
10)now you will find DATACONTEXT function here with name DataClassesDataContext,just remember it!
11)now come back to your Default.aspx & cs file and paste it on page load
12)Now Add a Grid View to your aspx page(if i am not wrong it will come up with a name GridView1)
13) Now 

        DataClassesDataContext dc=new DataClassesDataContext ();
        var q = from a in dc.GetTable<tbEmp1>() select a;
        GridView1.DataSource = q;
        GridView1.DataBind();
14)
Now if you've a confusion that why the sql query Are different here!
then my answer is "that the LINQ is"
select * from tbvijay
is same for LINQ as
from a in dc.
GetTable<tbVijay>() select a



15)
now just these lines and if you are aware of gridview you can do a lot from it!Because All Data Is In GridView!!

still i am giving you some more sql queries for LINQ

i)

 DataClasses1DataContext dc = new DataClasses1DataContext();
 var q = from a in dc.GetTable<Order>()      select a;
 GridView1.DataSource = q;
ii)DataClasses1DataContext dc = new DataClasses1DataContext();
    GridView1.DataSource = dc.GetTable<Order>();

iii)

DataClasses1DataContext dc = new DataClasses1DataContext();
 var q = from a in dc.GetTable<Order>() where a.CustomerID.StartsWith("A") select a;
    dataGridView1.DataSource = q;



iv)

DataClasses1DataContext
 dc = new DataClasses1DataContext();

     var q =  from a in dc.GetTable<Order>()where a.CustomerID == "VINET"  select a;
     dataGridView1.DataSource = q;


v)

DataClasses1DataContext dc = new DataClasses1DataContext();
  var q =   from a in dc.GetTable<Order>()  where a.CustomerID.StartsWith("A")orderby a.OrderDate ascending   select a;
   dataGridView1.DataSource = q;

vi)

DataClasses1DataContext dc = new DataClasses1DataContext();

    var q= (from orders in dc.GetTable<Order>()
            from orderDetails in dc.GetTable<Order_Detail>()
            from prods in dc.GetTable<Product>()
            where ((orderDetails.OrderID == orders.OrderID) &&
                 (prods.ProductID == orderDetails.ProductID) &&
                 (orders.EmployeeID == 1))
            orderby orders.ShipCountry
            select new CustomerOrderResult
            {
                CustomerID = orders.CustomerID,
                CustomerContactName = orders.Customer.ContactName,
                CustomerCountry = orders.Customer.Country,
                OrderDate = orders.OrderDate,
                EmployeeID = orders.Employee.EmployeeID,
                EmployeeFirstName = orders.Employee.FirstName,
                EmployeeLastName = orders.Employee.LastName,
                ProductName = prods.ProductName
            }).ToList<CustomerOrderResult>();

    dataGridView1.DataSource = q;



vii)

 DataClasses1DataContext dc = new DataClasses1DataContext();

    var query = (from orders in dc.GetTable<Order>()
             from orderDetails in dc.GetTable<Order_Detail>()
             from prods in dc.GetTable<Product>()
             where ((orderDetails.OrderID == orders.OrderID)
                  && (prods.ProductID == orderDetails.ProductID)
                  && (orders.EmployeeID == 1))
             orderby orders.ShipCountry
             select new CustomerOrderResult
             {
                 CustomerID = orders.CustomerID,
                 CustomerContactName = orders.Customer.ContactName,
                 CustomerCountry = orders.Customer.Country,
                 OrderDate = orders.OrderDate,
                 EmployeeID = orders.Employee.EmployeeID,
                 EmployeeFirstName = orders.Employee.FirstName,
                 EmployeeLastName = orders.Employee.LastName,
                 ProductName = prods.ProductName
             }).ToList<CustomerOrderResult>();

    var matches = (from c in query
                  where c.CustomerID == "RICAR"
                  select c).ToList<CustomerOrderResult>();

    dataGridView1.DataSource = matches;


viii)

DataClasses1DataContext dc = new DataClasses1DataContext();

    var query = (from orders in dc.GetTable<Order>()
                 select orders);

    var matches = (from c in query
                   where c.OrderID == 10248
                   select
                   c.Employee.LastName).SingleOrDefault<System.String>();

    MessageBox.Show(matches);




Hope it will work for you
Ask me if you have any further question!

Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...