Thursday, September 25, 2008

Difference between MVP and MVC pattern?

Here are the key differences between the patterns:

· MVP Pattern

o View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.

o Easier to unit test because interaction with the view is through an interface

o Usually view to presenter map one to one. Complex views may have multi presenters.


· MVC Pattern

o Controller are based on behaviors and can be shared across views

o Can be responsible for determining which view to display (Front Controller Pattern)

http://blogs.infragistics.com/blogs/tsnyder/archive/2007/10/17/mvc-or-mvp-pattern-whats-the-difference.aspx

Wednesday, September 24, 2008

Sample Source code for Bulk insert using OPENXML?

DECLARE @studentXML XML
DECLARE @xmlHandle INT
SET @studentXML = '



'
EXEC SP_XML_PREPAREDOCUMENT @xmlHandle OUTPUT, @studentXML
SELECT studentName
,studentID
INTO #student
FROM OPENXML( @xmlHandle, '/students/student', 1 )
WITH
(
studentName VARCHAR(10) '@name',
studentID VARCHAR(3) '@id'
)
EXEC SP_XML_REMOVEDOCUMENT @xmlHandle
SELECT * FROM #student
DROP TABLE #student

Please look at this link..
http://www.informit.com/articles/article.aspx?p=102307&seqNum=6

This is also good link to refer, bulk insert and update
http://sqlxml.org/faqs.aspx?faq=100

Monday, September 22, 2008

Friday, September 19, 2008

wha are new features of .net Framwork 3.5 service pack 1?

ASP.NET in the .NET Framework 3.5 Service Pack 1 release includes numerous bug fixes. In addition, it includes features for the following:

---Enabling high-productivity data scenarios by using ASP.NET Dynamic Data.
---Supporting the browser navigation in ASP.NET AJAX applications by using ASP.NET AJAX browser history.
---Increasing the download speed for ASP.NET applications by using ASP.NET AJAX script combining.

Friday, September 5, 2008

SQL Server Release history?




































































VersionYearRelease NameCodename
1.0

(OS/2)
1989SQL Server 1.0-
4.21

(WinNT)
1993SQL Server 4.21-
6.01995SQL Server 6.0SQL95
6.51996SQL Server 6.5Hydra
7.01998SQL Server 7.0Sphinx
-1999SQL Server 7.0

OLAP Tools
Plato
8.02000SQL Server 2000Shiloh
8.02003SQL Server 2000

64-bit Edition
Liberty
9.02005SQL Server 2005Yukon
10.02008SQL Server 2008Katmai

Thursday, September 4, 2008

LinQ sample Queries to Database?

Query the Customers from Database
//creating the datacontext instance
NorthwindDataClassesDataContext dc = new NorthwindDataClassesDataContext();

//Sample 1 : query all customers
var customers =
from c in dc.Customers
select c;

//display query result in a dataGridView
dataGridResult.DataSource = customers.ToList();
Query the Customers with a Simple Statement
//Sample 2 : query customers which country is UK
//constructing the query
var customers_from_uk =
from c in dc.Customers
where c.Country == "UK"
select c;

Query Multiple Tables
//Sample 3 : query customers and products
//(it makes a cross product it do not represent anything else than a query
var customers_and_product =
from c in dc.Customers
from p in dc.Products
where c.ContactName.StartsWith("A") && p.ProductName.StartsWith("P")
select new { Name = c.ContactName, Product = p.ProductName };
The resulting collection is the cross product between all contact names starting with "A" and all products starting with "P."

Query with Tables Joined
//Sample 4 : query customers and orders
var customers_and_orders =
from c in dc.Customers
from p in dc.Orders
where c.CustomerID == p.CustomerID
select new { c.ContactName, p.OrderID};

Query in the Old Way: with SQL as String
As you may want to execute SQL that is not yet supported by LINQ to SQL, a way to execute SQL queries in the old way is available.

//Sample 5 : execute SQL queries
dc.ExecuteCommand("UPDATE Customers SET PostalCode='05024' where CustomerId='ALFKI' ");
Insert


Insert, Update and Delete Rows from Database
LINQ to SQL provides a new way of managing data into database. The three SQL statements INSERT, DELETE and UPDATE are implemented, but using them is not visible.

Update Statement
//Sample 6 : updating data
var customers_in_paris =
from c in dc.Customers
where c.City.StartsWith("Paris")
select c;

foreach (var cust in customers_in_paris)
cust.City = "PARIS";

//modification to database are applied when SubmitChanges is called.
dc.SubmitChanges();
To make modifications to a database, just modify any relevant object properties and call the method SubmitChanges().

Insert Statement
To insert a new entry into the database, you just have to create an instance of a C# class and Attach it to the associated table.

//Sample 7 : inserting data
Product newProduct = new Product();
newProduct.ProductName = "RC helicopter";

dc.Products.Attach(newProduct);

dc.SubmitChanges();
Delete Statement
Deleting data is quite easy. When requesting your database, give a collection of data. Then just call DeleteOnSubmit (or DeleteAllOnSubmit) to delete the specified items.

//Sample 8 : deleting data
var products_to_delete =
from p in dc.Products
where p.ProductName.Contains("helicopter")
select p;

dc.Products.DeleteAllOnSubmit(products_to_delete);

dc.SubmitChanges();

Order of Operations
To use LINQ to SQL, a developer must know exactly when a query is executed. Indeed, LINQ to SQL is very powerful because the query is executed when it's required, but not at definition! In the first sample, we have this code:

///constructing the query
var customers =
from c in dc.Customers
select c;
The query is not yet executed; it is just compiled and analysed. In fact, the query is run when the code makes an access to the customer variable, like here:

//display query result in a dataGridView
dataGridResult.DataSource = customers.ToList();






What is LINQ to SQL?

LINQ to SQL is a new system which allows you to easily map tables, views and stored procedures from your SQL server. Moreover, LINQ to SQL helps developers in mapping and requesting a database with its simple and SQL-like language. It is not the ADO.NET replacement, but more an extension that provides new features.
**** LINQ to SQL only support for SQLServer not with any other databases

Wednesday, September 3, 2008

why Compiled queries(LINQ) are faster?

There are some drawbacks to LINQ to SQL. The Sql statement is built dynamically, so it is needed to parsed and compiled each time you run it. 
System.Data.Linq namespace includes a class named CompiledQuery which is responsible for caching the compiled version of a Linq to Sql query. 
****pre-compiled queries , that you can not use a stored-procedure to make a compiled query.

SQL query VS Parametrized queries?

SQL Query
---------
Dim sSQL As String = "SELECT FirstName, LastName, Title FROM Employees WHERE ((EmployeeID >" & sEmpId & " AND HireDate >#" & sHireDate & "#) AND Country = '" & sCountry & "')  

Our query take input values from variables that we defined before (sEmpId, sHireDate, sCountry) so we have to deal with various marker signs, such as quote (') to enclose our string variables and the pound sign (#) to enclose our date type variables. These are the rule of thumbs, so if you do not follow them, your query will not work! 

parameterized Query
-------------------

'Define our sql query
  Dim sSQL As String = "SELECT FirstName, LastName, Title " & _
                       "FROM Employees " & _
                       "WHERE ((EmployeeID > ? AND HireDate > ?) AND Country = ?)"

Take a look at the variable (sSQL) where we define our parameterized query. We use the question mark sign (?) for each input into the query. Notice that we use the question mark regardless of the type of our variable. To associated the parameter in the query we have to add parameters to the Parameters collection of the Command object. You can give the name of your parameter as whatever you want, as long as it's unique! Remember that you have to add the parameter in the same order as the order of the question mark signs that you put in your query! 

  oCmd.Parameters.Add("EmployeeID", sEmpId)
  oCmd.Parameters.Add("HireDate", sHireDate)
  oCmd.Parameters.Add("Country", sCountry)

***** Parameterized queries in SQL server are cached and resused

What is DataContext in LINQ?

DataContext is a class that gives direct access to C# classes, database connections etc. This class is genereated when the designer is saved. For a file named NorthwindDataClasses.dbml, the class NorthwindDataClassesDataContext is automatically generated. It contains the definition of tables and stored procedures.

What are the familiar javascript engines?

1. JScript (Internet Explorer)
2. SpiderMonkey (Firefox)
3. JavascriptCore (Safari)
4. V8 (Google Chrome)