http://channel9.msdn.com/blogs/matthijs/aspnet-mvc-2-basics-introduction-by-scott-hanselman
RouteDebug.RouteDebugger.RewriteRoutesForTesting
2010年12月29日星期三
2010年12月24日星期五
2010年12月21日星期二
Web Deployment Project
Deploy ASP.NET Web Applications with Web Deployment Projects
http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/
Web Deployment Projects
http://msdn.microsoft.com/en-us/magazine/cc163448.aspx
http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/
Web Deployment Projects
http://msdn.microsoft.com/en-us/magazine/cc163448.aspx
2010年12月1日星期三
Silverlight
http://www.silverlight.net/
An Introduction to Developing Applications for Microsoft Silverlight
http://live.visitmix.com/MIX10/Sessions/CL15
An Introduction to Developing Applications for Microsoft Silverlight
http://live.visitmix.com/MIX10/Sessions/CL15
2010年11月30日星期二
Make Ajax Calls Using jQuery
http://www.asp.net/ajax/videos/how-do-i-make-ajax-calls-using-jquery
In this video Chris Pels shows how to make Ajax calls using the jQuery library. A sample web site is created that contains a simple web service which returns a value. Next, the jQuery ajax() method is used to call the web service. A number of the ajax() method options are set including url, dataType, data, etc. In addition, event handlers for both success and error conditions are defined. Another web services is then defined which accepts an argument and also returns a value. A second ajax() call is defined that passes a value to the web service call and processes the return data. Finally, the setup for global options and event handlers for ajax() method calls are discussed.


In this video Chris Pels shows how to make Ajax calls using the jQuery library. A sample web site is created that contains a simple web service which returns a value. Next, the jQuery ajax() method is used to call the web service. A number of the ajax() method options are set including url, dataType, data, etc. In addition, event handlers for both success and error conditions are defined. Another web services is then defined which accepts an argument and also returns a value. A second ajax() call is defined that passes a value to the web service call and processes the return data. Finally, the setup for global options and event handlers for ajax() method calls are discussed.


Reducing Code by Using jQuery Templates
Reducing Code by Using jQuery Templates
http://weblogs.asp.net/dwahlin/archive/2010/11/20/reducing-code-by-using-jquery-templates.aspx
Not Using jQuery JavaScript Templates? You’re Really Missing Out.
http://blog.reybango.com/2010/07/09/not-using-jquery-javascript-templates-youre-really-missing-out/
http://weblogs.asp.net/dwahlin/archive/2010/11/20/reducing-code-by-using-jquery-templates.aspx
Not Using jQuery JavaScript Templates? You’re Really Missing Out.
http://blog.reybango.com/2010/07/09/not-using-jquery-javascript-templates-youre-really-missing-out/
2010年11月29日星期一
Some code-snippet in GridView, ListView control
Comparing ListView with GridView,DataList and Repeater
http://weblogs.asp.net/anasghanem/archive/2008/09/06/comparing-listview-with-gridview-datalist-and-repeater.aspx
1. ListViewItem listEditItem = lvJournals.Items[lvJournals.EditIndex];
2. protected void odsJournals_Updating(object Sender, ObjectDataSourceMethodEventArgs E)
{
E.InputParameters["JournalId"] = GetCurrentColumnItemId();
E.InputParameters["ModifiedBy"] = LogonUser.FullName;
3. protected override void CurrentFormObjectDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{
if (e.InputParameters[0] != null && e.InputParameters[0].GetType().Equals(typeof(tblRole_NEW)))
{
tblRole_NEW r = (tblRole_NEW)e.InputParameters[0];
r.ApplicationName = SelectedApplicationName;
}
base.CurrentFormObjectDataSource_Inserting(sender, e);
}
4. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim rw As GridViewRow = GridView1.Rows(e.RowIndex)
Dim dt As Data.DataTable = CType(Session("SavData"), Data.DataTable)
Dim prodid As String = CType(rw.Cells(1).Controls(0), TextBox).Text
Dim prodname As String = CType(rw.Cells(2).Controls(0), TextBox).Text
Dim supid As String = CType(rw.Cells(3).Controls(0), TextBox).Text
Dim catid As String = CType(rw.Cells(4).Controls(0), TextBox).Text
Dim old_prodid As String = dt.Rows(e.RowIndex).Item("productid")
Dim old_prodname As String = dt.Rows(e.RowIndex).Item("ProductName")
Dim old_supid As String = dt.Rows(e.RowIndex).Item("SupplierID")
Dim old_catid As String = dt.Rows(e.RowIndex).Item("CategoryID")
5. protected override void CurrentFormObjectDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
if (!DisableGridView && CurrentGrid.SelectedDataKey != null && CurrentGrid.SelectedDataKey["RoleName"] != null && CurrentGrid.SelectedDataKey["ApplicationName"] != null)
{
e.InputParameters["applicationName"] = (string)CurrentGrid.SelectedDataKey["ApplicationName"];
e.InputParameters["roleName"] = (string)CurrentGrid.SelectedDataKey["RoleName"];
}
else
e.Cancel = true;
base.CurrentFormObjectDataSource_Selecting(sender, e);
}
6. string ID = GridView1.DataKeys[e.RowIndex].Value.ToString();
asp:gridview id="CustomersGridView" datakeynames="CustomerID" runat="server">
/asp:gridview>
7. SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
8. lbDelete.OnClientClick = "javascript:return confirm('" + AppStrings.ctlEventList_DeleteAlert + "');";
9. asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete" CommandArgument='<%# Container.DataItemIndex %>' Text="Delete">
CurrentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
switch (e.CommandName.ToLower())
{
case "select":
CurrentGrid.SelectedIndex = Convert.ToInt32(e.CommandArgument);
...
}
10.
protected virtual void CurrentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
...
GridViewRow row = GetGridViewRow(e.CommandSource as Control);
...
}
protected GridViewRow GetGridViewRow(Control cntr)
{
if (cntr != null)
{
if (cntr.GetType().Equals(typeof(GridViewRow)))
return cntr as GridViewRow;
else
return GetGridViewRow(cntr.Parent);
}
return null;
}
11.
CurrentGridObjectDataSource_Updating
CurrentGridObjectDataSource_Updated
CurrentForm_ItemUpdated
CurrentForm_ModeChanging
CurrentForm_ModeChanged
CurrentGridObjectDataSource_Selecting
CurrentForm_ItemCreated
http://weblogs.asp.net/anasghanem/archive/2008/09/06/comparing-listview-with-gridview-datalist-and-repeater.aspx
1. ListViewItem listEditItem = lvJournals.Items[lvJournals.EditIndex];
2. protected void odsJournals_Updating(object Sender, ObjectDataSourceMethodEventArgs E)
{
E.InputParameters["JournalId"] = GetCurrentColumnItemId();
E.InputParameters["ModifiedBy"] = LogonUser.FullName;
3. protected override void CurrentFormObjectDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{
if (e.InputParameters[0] != null && e.InputParameters[0].GetType().Equals(typeof(tblRole_NEW)))
{
tblRole_NEW r = (tblRole_NEW)e.InputParameters[0];
r.ApplicationName = SelectedApplicationName;
}
base.CurrentFormObjectDataSource_Inserting(sender, e);
}
4. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim rw As GridViewRow = GridView1.Rows(e.RowIndex)
Dim dt As Data.DataTable = CType(Session("SavData"), Data.DataTable)
Dim prodid As String = CType(rw.Cells(1).Controls(0), TextBox).Text
Dim prodname As String = CType(rw.Cells(2).Controls(0), TextBox).Text
Dim supid As String = CType(rw.Cells(3).Controls(0), TextBox).Text
Dim catid As String = CType(rw.Cells(4).Controls(0), TextBox).Text
Dim old_prodid As String = dt.Rows(e.RowIndex).Item("productid")
Dim old_prodname As String = dt.Rows(e.RowIndex).Item("ProductName")
Dim old_supid As String = dt.Rows(e.RowIndex).Item("SupplierID")
Dim old_catid As String = dt.Rows(e.RowIndex).Item("CategoryID")
5. protected override void CurrentFormObjectDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
if (!DisableGridView && CurrentGrid.SelectedDataKey != null && CurrentGrid.SelectedDataKey["RoleName"] != null && CurrentGrid.SelectedDataKey["ApplicationName"] != null)
{
e.InputParameters["applicationName"] = (string)CurrentGrid.SelectedDataKey["ApplicationName"];
e.InputParameters["roleName"] = (string)CurrentGrid.SelectedDataKey["RoleName"];
}
else
e.Cancel = true;
base.CurrentFormObjectDataSource_Selecting(sender, e);
}
6. string ID = GridView1.DataKeys[e.RowIndex].Value.ToString();
asp:gridview id="CustomersGridView" datakeynames="CustomerID" runat="server">
/asp:gridview>
7. SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
8. lbDelete.OnClientClick = "javascript:return confirm('" + AppStrings.ctlEventList_DeleteAlert + "');";
9. asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete" CommandArgument='<%# Container.DataItemIndex %>' Text="Delete">
CurrentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
switch (e.CommandName.ToLower())
{
case "select":
CurrentGrid.SelectedIndex = Convert.ToInt32(e.CommandArgument);
...
}
10.
protected virtual void CurrentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
...
GridViewRow row = GetGridViewRow(e.CommandSource as Control);
...
}
protected GridViewRow GetGridViewRow(Control cntr)
{
if (cntr != null)
{
if (cntr.GetType().Equals(typeof(GridViewRow)))
return cntr as GridViewRow;
else
return GetGridViewRow(cntr.Parent);
}
return null;
}
11.
CurrentGridObjectDataSource_Updating
CurrentGridObjectDataSource_Updated
CurrentForm_ItemUpdated
CurrentForm_ModeChanging
CurrentForm_ModeChanged
CurrentGridObjectDataSource_Selecting
CurrentForm_ItemCreated
2010年11月18日星期四
2010年11月15日星期一
2010年10月25日星期一
2010年9月18日星期六
2010年8月26日星期四
CSS
The Floating Boxes CSS Layout
http://matthewjamestaylor.com/blog/floating-boxes-css-layout
Liquid layouts the easy way
http://www.maxdesign.com.au/articles/liquid/
Cascading Style Sheets in Visual Studio 2008
http://www.asp.net/aspnet-35/videos/how-do-i-cascading-style-sheets-in-visual-studio-2008
Adding Elements to a CSS File and Create New CSS on the Fly
http://www.asp.net/aspnet-35/videos/how-do-i-adding-elements-to-a-css-file-and-create-new-css-on-the-fly
CSS Properties/Manage Styles/Apply Styles
Styple Application toolbar -> Show Overlay
http://matthewjamestaylor.com/blog/floating-boxes-css-layout
Liquid layouts the easy way
http://www.maxdesign.com.au/articles/liquid/
Cascading Style Sheets in Visual Studio 2008
http://www.asp.net/aspnet-35/videos/how-do-i-cascading-style-sheets-in-visual-studio-2008
Adding Elements to a CSS File and Create New CSS on the Fly
http://www.asp.net/aspnet-35/videos/how-do-i-adding-elements-to-a-css-file-and-create-new-css-on-the-fly
CSS Properties/Manage Styles/Apply Styles
Styple Application toolbar -> Show Overlay
2010年8月25日星期三
2010年8月20日星期五
2010年8月19日星期四
.Net Open Source
http://www.asp.net/community/projects#jm_content_management
A CMS Web Portal open source project
http://www.mojoportal.com/
http://mojoportal.codeplex.com/
A CMS Web Portal open source project
http://www.mojoportal.com/
http://mojoportal.codeplex.com/
2010年8月18日星期三
2010年8月16日星期一
Introduction to Data Concurrency in ADO.NET
http://msdn.microsoft.com/en-us/library/cs6hb8k4(VS.80).aspx
ADO.NET and Visual Studio use optimistic concurrency, because the data architecture is based on disconnected data. Therefore, you need to add business logic to resolve issues with optimistic concurrency.
ADO.NET and Visual Studio use optimistic concurrency, because the data architecture is based on disconnected data. Therefore, you need to add business logic to resolve issues with optimistic concurrency.
HTTP Handlers and HTTP Modules Overview
http://msdn.microsoft.com/en-us/library/bb398986.aspx
An ASP.NET HTTP handler is the process (frequently referred to as the "endpoint") that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.
An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.
Typical uses for custom HTTP handlers include the following:
o RSS feeds To create an RSS feed for a Web site, you can create a handler that emits RSS-formatted XML. You can then bind a file name extension such as .rss to the custom handler. When users send a request to your site that ends in .rss, ASP.NET calls your handler to process the request.
o Image server If you want a Web application to serve images in a variety of sizes, you can write a custom handler to resize images and then send them to the user as the handler's response.
Typical uses for HTTP modules include the following:
o Security Because you can examine incoming requests, an HTTP module can perform custom authentication or other security checks before the requested page, XML Web service, or handler is called. In Internet Information Services (IIS) 7.0 running in Integrated mode, you can extend forms authentication to all content types in an application.
o Statistics and logging Because HTTP modules are called on every request, you can gather request statistics and log information in a centralized module, instead of in individual pages.
o Custom headers or footers Because you can modify the outgoing response, you can insert content such as custom header information into every page or XML Web service response.
An ASP.NET HTTP handler is the process (frequently referred to as the "endpoint") that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.
An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.
Typical uses for custom HTTP handlers include the following:
o RSS feeds To create an RSS feed for a Web site, you can create a handler that emits RSS-formatted XML. You can then bind a file name extension such as .rss to the custom handler. When users send a request to your site that ends in .rss, ASP.NET calls your handler to process the request.
o Image server If you want a Web application to serve images in a variety of sizes, you can write a custom handler to resize images and then send them to the user as the handler's response.
Typical uses for HTTP modules include the following:
o Security Because you can examine incoming requests, an HTTP module can perform custom authentication or other security checks before the requested page, XML Web service, or handler is called. In Internet Information Services (IIS) 7.0 running in Integrated mode, you can extend forms authentication to all content types in an application.
o Statistics and logging Because HTTP modules are called on every request, you can gather request statistics and log information in a centralized module, instead of in individual pages.
o Custom headers or footers Because you can modify the outgoing response, you can insert content such as custom header information into every page or XML Web service response.
2010年8月12日星期四
What is WSDL?
WSDL stands for Web Services Description Language
WSDL is written in XML
WSDL is an XML document
WSDL is used to describe Web services
WSDL is also used to locate Web services
WSDL is a W3C recommendation
The main structure of a WSDL document looks like this:
definition of types........
definition of a message....
definition of a port.......
definition of a binding....
WSDL Ports
The element is the most important WSDL element.
It describes a web service, the operations that can be performed, and the messages that are involved.
The element can be compared to a function library (or a module, or a class) in a traditional programming language.
WSDL Messages
The element defines the data elements of an operation.
Each message can consist of one or more parts. The parts can be compared to the parameters of a function call in a traditional programming language.
WSDL Types
The element defines the data types that are used by the web service.
For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.
WSDL Bindings
The element defines the message format and protocol details for each port.
WSDL Example
This is a simplified fraction of a WSDL document:
WSDL is written in XML
WSDL is an XML document
WSDL is used to describe Web services
WSDL is also used to locate Web services
WSDL is a W3C recommendation
The main structure of a WSDL document looks like this:
definition of types........
definition of a message....
definition of a port.......
definition of a binding....
WSDL Ports
The
It describes a web service, the operations that can be performed, and the messages that are involved.
The
WSDL Messages
The
Each message can consist of one or more parts. The parts can be compared to the parameters of a function call in a traditional programming language.
WSDL Types
The
For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.
WSDL Bindings
The
WSDL Example
This is a simplified fraction of a WSDL document:
What is endpoint?
All communication with a Windows Communication Foundation (WCF) service occurs through the endpoints of the service. Endpoints provide clients access to the functionality offered by a WCF service.
You can define one or more endpoints for a service by using a combination of relative and absolute endpoint addresses, or if you do not define any service endpoints, the runtime provides some by default for you.
Each endpoint consists of four properties:
•An address that indicates where the endpoint can be found.
•A binding that specifies how a client can communicate with the endpoint.
•A contract that identifies the operations available.
•A set of behaviors that specify local implementation details of the endpoint.
You can specify the endpoint for a service either imperatively using code or declaratively through configuration.
http://msdn.microsoft.com/en-us/library/ms734786.aspx
You can define one or more endpoints for a service by using a combination of relative and absolute endpoint addresses, or if you do not define any service endpoints, the runtime provides some by default for you.
Each endpoint consists of four properties:
•An address that indicates where the endpoint can be found.
•A binding that specifies how a client can communicate with the endpoint.
•A contract that identifies the operations available.
•A set of behaviors that specify local implementation details of the endpoint.
You can specify the endpoint for a service either imperatively using code or declaratively through configuration.
http://msdn.microsoft.com/en-us/library/ms734786.aspx
What is Fine-grained Service? What is coarse-grained service?
http://articles.techrepublic.com.com/5100-10878_11-5064520.html
Fine-grained services might be services that provide a small amount of business-process usefulness, such as basic data access.
Slightly more coarse-grained services might provide rudimentary operations, which are valuable to system experts, but are not much value to a business-process expert.
Services of the most value to business experts are constructed from low-level services, components, and objects that are intelligently structured to meet specific business needs. These coarse-grained services can be created from one or more existing systems by defining and exposing interfaces that meet business-process requirements.
Services as composite interfaces
Using coarse-grained interfaces, a system of services controls access to the objects referenced by each service. While each service may be implemented as an abstraction on a group of finer-grained objects, the objects themselves can be hidden from public access. Each service can be implemented by grouping objects, components, and fine-grained services, and exposing them as a single unit through the use of facades or interfaces
Fine-grained services might be services that provide a small amount of business-process usefulness, such as basic data access.
Slightly more coarse-grained services might provide rudimentary operations, which are valuable to system experts, but are not much value to a business-process expert.
Services of the most value to business experts are constructed from low-level services, components, and objects that are intelligently structured to meet specific business needs. These coarse-grained services can be created from one or more existing systems by defining and exposing interfaces that meet business-process requirements.
Services as composite interfaces
Using coarse-grained interfaces, a system of services controls access to the objects referenced by each service. While each service may be implemented as an abstraction on a group of finer-grained objects, the objects themselves can be hidden from public access. Each service can be implemented by grouping objects, components, and fine-grained services, and exposing them as a single unit through the use of facades or interfaces
2010年8月8日星期日
2010年8月7日星期六
Web Services development using the .NET SDK alone
http://www.codeguru.com/Csharp/Csharp/cs_webservices/tutorials/article.php/c5477
c:> WSDL http://localhost/MyWebServices/FirstService.asmx?WSDL
c:> csc /t:library FirstService.cs
Create a proxy for the Web Service using the wsdl utility supplied with the .NET SDK. It will create FirstSevice.cs in the current directory. We need to compile it to create FirstService.dll (proxy) for the Web Service.
c:> WSDL http://localhost/MyWebServices/FirstService.asmx?WSDL
c:> csc /t:library FirstService.cs
Create a proxy for the Web Service using the wsdl utility supplied with the .NET SDK. It will create FirstSevice.cs in the current directory. We need to compile it to create FirstService.dll (proxy) for the Web Service.
2010年8月6日星期五
Working with Visual Studio 2010
Part 1
http://www.youtube.com/watch?v=mVKYgr-QOow
Part 2
http://www.youtube.com/watch?v=bYLaONWEJOg&feature=related
Part 3
http://www.youtube.com/watch?v=-wg4ugYOhzo&feature=related
Part 4
http://www.youtube.com/watch?v=DfCpyB_fsIg&feature=related
Part 5
http://www.youtube.com/watch?v=P6d9rJkqsfA&feature=related
Part 6 checking
http://www.youtube.com/watch?v=et2OzceM4rw&feature=related
Part 7
http://www.youtube.com/watch?v=Dl7ZDbTJAdo&feature=related
Part 8
http://www.youtube.com/watch?v=C8XxojT-6sc&feature=related
Part 9
I show how to fix a bug reported by the tester, how the tester can verify the bug fix and finally how to close the bug.
http://www.youtube.com/watch?v=XWPLybAptJ8&feature=related
Part 10
http://www.youtube.com/watch?v=B-TvSUQlrUw&feature=related
Part 11
http://www.youtube.com/watch?v=AAzYFraNe6I&feature=related
http://www.youtube.com/watch?v=mVKYgr-QOow
Part 2
http://www.youtube.com/watch?v=bYLaONWEJOg&feature=related
Part 3
http://www.youtube.com/watch?v=-wg4ugYOhzo&feature=related
Part 4
http://www.youtube.com/watch?v=DfCpyB_fsIg&feature=related
Part 5
http://www.youtube.com/watch?v=P6d9rJkqsfA&feature=related
Part 6 checking
http://www.youtube.com/watch?v=et2OzceM4rw&feature=related
Part 7
http://www.youtube.com/watch?v=Dl7ZDbTJAdo&feature=related
Part 8
http://www.youtube.com/watch?v=C8XxojT-6sc&feature=related
Part 9
I show how to fix a bug reported by the tester, how the tester can verify the bug fix and finally how to close the bug.
http://www.youtube.com/watch?v=XWPLybAptJ8&feature=related
Part 10
http://www.youtube.com/watch?v=B-TvSUQlrUw&feature=related
Part 11
http://www.youtube.com/watch?v=AAzYFraNe6I&feature=related
IE8 Developer Tools
Sceencast: Introduction to the IE8 Developer Tools
http://www.youtube.com/watch?v=DRdhertDzgM
http://www.youtube.com/watch?v=DRdhertDzgM
2010年7月28日星期三
2010年7月27日星期二
Using jQuery in ASP.Net AJAX Applications
http://www.codedigest.com/Articles/ASPNETAJAX/183_Using_JQuery_in_ASPNet_AJAX_Applications_%e2%80%93_Part_1.aspx
we implemented the server side functionality using a separate aspx page and it is called through the AJAX methods available in JQuery.
We made AJAX calls through POST and GET method using JQuery library.
http://www.codedigest.com/Articles/ASPNETAJAX/185_Using_JQuery_in_ASPNet_AJAX_Applications%E2%80%93Part_2.aspx
Server side functionality can be very well implemented through a mere server side function instead of a separate page.
To implement the requirement through PageMethods, we need to define a function in codebehind and decorate it with an attribute called WebMethod. To call this PageMethods from JavaScript, we need to enable the EnablePageMethods property of ScriptManager to true. This will create a JavaScript proxy for all the page methods declared in the page and it will be injected to the client side. We can use JQuery.ajax() method to call the PageMethod from client side.
we implemented the server side functionality using a separate aspx page and it is called through the AJAX methods available in JQuery.
We made AJAX calls through POST and GET method using JQuery library.
http://www.codedigest.com/Articles/ASPNETAJAX/185_Using_JQuery_in_ASPNet_AJAX_Applications%E2%80%93Part_2.aspx
Server side functionality can be very well implemented through a mere server side function instead of a separate page.
To implement the requirement through PageMethods, we need to define a function in codebehind and decorate it with an attribute called WebMethod. To call this PageMethods from JavaScript, we need to enable the EnablePageMethods property of ScriptManager to true. This will create a JavaScript proxy for all the page methods declared in the page and it will be injected to the client side. We can use JQuery.ajax() method to call the PageMethod from client side.
2010年7月23日星期五
Security
Cross Site Scripting
http://www.owasp.org/index.php/Top_10_2007-Cross_Site_Scripting
How To: Prevent Cross-Site Scripting in ASP.NET
http://msdn.microsoft.com/en-us/library/ff649310.aspx
The two most important countermeasures to prevent cross-site scripting attacks are to:
•Constrain input.
•Encode output.
Security Design Principles - Input/Data Validation
http://www.guidanceshare.com/wiki/Security_Design_Principles_-_Input/Data_Validation
http://www.owasp.org/index.php/Top_10_2007-Cross_Site_Scripting
How To: Prevent Cross-Site Scripting in ASP.NET
http://msdn.microsoft.com/en-us/library/ff649310.aspx
The two most important countermeasures to prevent cross-site scripting attacks are to:
•Constrain input.
•Encode output.
Security Design Principles - Input/Data Validation
http://www.guidanceshare.com/wiki/Security_Design_Principles_-_Input/Data_Validation
TRY...CATCH in SQL Server 2005
http://www.4guysfromrolla.com/webtech/041906-1.shtml
because the @@ERROR variable is set after every SQL statement. Therefore, if the first DELETE statement has an error the @@ERROR variable will be set to its error number. Then, the second DELETE will execute. If this second DELETE succeeds, @@ERROR will be set back to 0, in which case the transaction will be committed even though there was a problem with the first statement! Whoops!
The SQL Server 2005 TRY...CATCH block executes a number of statements in the TRY block. If there are no errors in any of the statements, control proceeds to after the CATCH block. If, however, one of the statements causes an error, control branches immediately to the start of the CATCH block.
CREATE PROCEDURE DeleteEmployee ( @EmployeeID int )
AS
BEGIN TRY
BEGIN TRANSACTION -- Start the transaction
-- Delete the Employee's phone numbers
DELETE FROM EmployeePhoneNumbers
WHERE EmployeeID = @EmployeeID
-- Delete the Employee record
DELETE FROM Employees
WHERE EmployeeID = @EmployeeID
-- If we reach here, success!
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
because the @@ERROR variable is set after every SQL statement. Therefore, if the first DELETE statement has an error the @@ERROR variable will be set to its error number. Then, the second DELETE will execute. If this second DELETE succeeds, @@ERROR will be set back to 0, in which case the transaction will be committed even though there was a problem with the first statement! Whoops!
The SQL Server 2005 TRY...CATCH block executes a number of statements in the TRY block. If there are no errors in any of the statements, control proceeds to after the CATCH block. If, however, one of the statements causes an error, control branches immediately to the start of the CATCH block.
CREATE PROCEDURE DeleteEmployee ( @EmployeeID int )
AS
BEGIN TRY
BEGIN TRANSACTION -- Start the transaction
-- Delete the Employee's phone numbers
DELETE FROM EmployeePhoneNumbers
WHERE EmployeeID = @EmployeeID
-- Delete the Employee record
DELETE FROM Employees
WHERE EmployeeID = @EmployeeID
-- If we reach here, success!
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
2010年7月22日星期四
channel9
channel9 Videos
http://channel9.msdn.com/Media/Videos/#Page=1
channel9 Course
http://channel9.msdn.com/learn/courses/
http://channel9.msdn.com/Media/Videos/#Page=1
channel9 Course
http://channel9.msdn.com/learn/courses/
SQL Server stuffs
SQL 2008 Series: Triggers
http://www.youtube.com/watch?v=URs_rnzkmxs&feature=related
Trigger in SQL Server 2005 tutorial from wingslive.com
http://www.youtube.com/watch?v=5zyQIt-8NRQ&feature=related
SQL 2008 Series: Views
http://www.youtube.com/watch?v=to_0_bODY2Y&feature=channel
SQL Server 2008 T-SQL Debugger
http://www.youtube.com/watch?v=618LE_FZCxI&feature=related
Microsoft SQL Server 2005: Execution Plans
http://www.youtube.com/watch?v=uGi7_LkJXFI&feature=related
Using Statistics to Improve Query Performance
http://msdn.microsoft.com/en-us/library/ms190397.aspx
DBCC SHOW_STATISTICS (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms174384.aspx
Performance Tuning in SQL Server (GOOD)
http://www.youtube.com/watch?v=P97_oFfD218&NR=1
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
SET STATISTICS IO ON
SET STATISTICS TIME ON
1. Limit the number of columns returned
2. Create primary key on table
3. Create an Index on the columns in the WHERE clause
4. Limit the number of rows by using TOP
5. When working with joins, have an index on the columns in the JOIN and where clause
6. If you use multiple columns in WHERE or ORDER BY, create compound index, pay attention to the order of index
7. If you are trying to get unique values, use GROUP BY instead of DISTINCT
SQL Server 2008 Query Optimization - Part IV
http://www.youtube.com/watch?v=QFyJ2NtebzM&feature=channel
8. Use EXISTS instead of IN clause for sub queries
9. Use SET NOCOUNT OFF
Database Management Tool - SQL Server Profiler
http://www.youtube.com/watch?v=1RLuHzkyQy4
SQL Joins, nested loops and all that in less than 6 minutes
http://www.youtube.com/watch?v=SmDZaH855qE&feature=related
Rewriting SQL queries for Performance in 9 minutes (GOOD)
http://www.youtube.com/watch?v=ZVisY-fEoMw&feature=related
1. Try to remove the rows that not be able to seen in the final result set ASAP
2. group and sort as little column as possible
3. Join late
Query Tuning
http://msdn.microsoft.com/en-us/library/ms176005.aspx
General Index Design Guidelines
http://msdn.microsoft.com/en-us/library/ms191195.aspx
SET ANSI_NULLS { ON | OFF }
When SET ANSI_NULLS is ON, a SELECT statement that uses WHERE column_name = NULL returns zero rows even if there are null values in column_name. A SELECT statement that uses WHERE column_name <> NULL returns zero rows even if there are nonnull values in column_name.
SET QUOTED_IDENTIFIER { ON | OFF }
When SET QUOTED_IDENTIFIER is ON (default), identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers.
http://www.youtube.com/watch?v=URs_rnzkmxs&feature=related
Trigger in SQL Server 2005 tutorial from wingslive.com
http://www.youtube.com/watch?v=5zyQIt-8NRQ&feature=related
SQL 2008 Series: Views
http://www.youtube.com/watch?v=to_0_bODY2Y&feature=channel
SQL Server 2008 T-SQL Debugger
http://www.youtube.com/watch?v=618LE_FZCxI&feature=related
Microsoft SQL Server 2005: Execution Plans
http://www.youtube.com/watch?v=uGi7_LkJXFI&feature=related
Using Statistics to Improve Query Performance
http://msdn.microsoft.com/en-us/library/ms190397.aspx
DBCC SHOW_STATISTICS (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms174384.aspx
Performance Tuning in SQL Server (GOOD)
http://www.youtube.com/watch?v=P97_oFfD218&NR=1
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
SET STATISTICS IO ON
SET STATISTICS TIME ON
1. Limit the number of columns returned
2. Create primary key on table
3. Create an Index on the columns in the WHERE clause
4. Limit the number of rows by using TOP
5. When working with joins, have an index on the columns in the JOIN and where clause
6. If you use multiple columns in WHERE or ORDER BY, create compound index, pay attention to the order of index
7. If you are trying to get unique values, use GROUP BY instead of DISTINCT
SQL Server 2008 Query Optimization - Part IV
http://www.youtube.com/watch?v=QFyJ2NtebzM&feature=channel
8. Use EXISTS instead of IN clause for sub queries
9. Use SET NOCOUNT OFF
Database Management Tool - SQL Server Profiler
http://www.youtube.com/watch?v=1RLuHzkyQy4
SQL Joins, nested loops and all that in less than 6 minutes
http://www.youtube.com/watch?v=SmDZaH855qE&feature=related
Rewriting SQL queries for Performance in 9 minutes (GOOD)
http://www.youtube.com/watch?v=ZVisY-fEoMw&feature=related
1. Try to remove the rows that not be able to seen in the final result set ASAP
2. group and sort as little column as possible
3. Join late
Query Tuning
http://msdn.microsoft.com/en-us/library/ms176005.aspx
General Index Design Guidelines
http://msdn.microsoft.com/en-us/library/ms191195.aspx
SET ANSI_NULLS { ON | OFF }
When SET ANSI_NULLS is ON, a SELECT statement that uses WHERE column_name = NULL returns zero rows even if there are null values in column_name. A SELECT statement that uses WHERE column_name <> NULL returns zero rows even if there are nonnull values in column_name.
SET QUOTED_IDENTIFIER { ON | OFF }
When SET QUOTED_IDENTIFIER is ON (default), identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers.
Logic Data Modeling
1 - Introduction
http://www.youtube.com/watch?v=IiVq8M5DBkk&feature=channel
2 - Candidate Key
http://www.youtube.com/watch?v=BGMwuOtRfqU&feature=channel
3 - Normalization
http://www.youtube.com/watch?v=ZiB-BKCzS_I&feature=channel
4 - Normalization Example
http://www.youtube.com/watch?v=pJ47btpjAhA&feature=channel
5 - 1st Normal Form
http://www.youtube.com/watch?v=q3Wg2fZENK0&feature=channel
6 - Process & Data: Data Flow Diagram
http://www.youtube.com/watch?v=X9MyqHGPDaI&feature=related
7 - 3rd Normal Form
http://www.youtube.com/watch?v=HH-QR7t-kMo&feature=related
8 - Entity Relationship Diagram, part 1
http://www.youtube.com/watch?v=q1GaaGHHAqM&feature=related
9 - Entity Relationship Diagram, part 2
http://www.youtube.com/watch?v=lXAGQ8vmhCY&feature=related
http://www.youtube.com/watch?v=IiVq8M5DBkk&feature=channel
2 - Candidate Key
http://www.youtube.com/watch?v=BGMwuOtRfqU&feature=channel
3 - Normalization
http://www.youtube.com/watch?v=ZiB-BKCzS_I&feature=channel
4 - Normalization Example
http://www.youtube.com/watch?v=pJ47btpjAhA&feature=channel
5 - 1st Normal Form
http://www.youtube.com/watch?v=q3Wg2fZENK0&feature=channel
6 - Process & Data: Data Flow Diagram
http://www.youtube.com/watch?v=X9MyqHGPDaI&feature=related
7 - 3rd Normal Form
http://www.youtube.com/watch?v=HH-QR7t-kMo&feature=related
8 - Entity Relationship Diagram, part 1
http://www.youtube.com/watch?v=q1GaaGHHAqM&feature=related
9 - Entity Relationship Diagram, part 2
http://www.youtube.com/watch?v=lXAGQ8vmhCY&feature=related
Entity Data Model
ADO.NET Tech Preview: Entity Data Model
http://msdn.microsoft.com/en-us/library/aa697428(VS.80).aspx
http://msdn.microsoft.com/en-us/library/aa697428(VS.80).aspx
Entity Framework
The Entity Framework vs. The Data Access Layer (Part 0: Introduction)
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/04/27/the-entity-framework-vs-the-data-access-layer-part-0-introduction.aspx
The Entity Framework vs. The Data Access Layer (Part 1: The EF as a DAL)
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/05/06/the-entity-framework-vs-the-data-access-layer-part-1-the-ef-as-a-dal.aspx
ADO.NET Entity Framework .Net 4.0
http://msdn.microsoft.com/en-us/library/bb399572.aspx
Get Started with the Entity Framework
http://www.asp.net/aspnet-35/videos/how-do-i-get-started-with-the-entity-framework
Use the New Entity Data Source
http://www.asp.net/aspnet-35/videos/how-do-i-use-the-new-entity-data-source
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/04/27/the-entity-framework-vs-the-data-access-layer-part-0-introduction.aspx
The Entity Framework vs. The Data Access Layer (Part 1: The EF as a DAL)
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/05/06/the-entity-framework-vs-the-data-access-layer-part-1-the-ef-as-a-dal.aspx
ADO.NET Entity Framework .Net 4.0
http://msdn.microsoft.com/en-us/library/bb399572.aspx
Get Started with the Entity Framework
http://www.asp.net/aspnet-35/videos/how-do-i-get-started-with-the-entity-framework
Use the New Entity Data Source
http://www.asp.net/aspnet-35/videos/how-do-i-use-the-new-entity-data-source
Windows Communication Foundation
Windows Communication Foundation
.Net 3.5 http://msdn.microsoft.com/en-us/library/ms735119.aspx
.Net 4.0 http://msdn.microsoft.com/en-us/library/dd456779.aspx
Getting Started Tutorial
http://msdn.microsoft.com/en-us/library/ms734712.aspx
What Is Windows Communication Foundation
http://msdn.microsoft.com/en-us/library/ms731082.aspx
WCF Samples
http://msdn.microsoft.com/en-us/library/ms730936.aspx
.Net 3.5 http://msdn.microsoft.com/en-us/library/ms735119.aspx
.Net 4.0 http://msdn.microsoft.com/en-us/library/dd456779.aspx
Getting Started Tutorial
http://msdn.microsoft.com/en-us/library/ms734712.aspx
What Is Windows Communication Foundation
http://msdn.microsoft.com/en-us/library/ms731082.aspx
WCF Samples
http://msdn.microsoft.com/en-us/library/ms730936.aspx
2010年7月20日星期二
System Exception & Application Exception
You can find them in Visual Studio, Debug -> Exceptions...
System.Data.SqlClient.SqlException
System.IO.IOException
System.ArgumentException
System.NullReferenceException
System.OutOfMemoryException
System.OverflowException
System.DivideByZeroExecption
...
Two categories of exceptions exist under the base class Exception:
•The pre-defined common language runtime exception classes derived from SystemException.
•The user-defined application exception classes derived from ApplicationException.
User applications, not the common language runtime, throw custom exceptions derived from the ApplicationException class. The ApplicationException class differentiates between exceptions defined by applications versus exceptions defined by the system.
If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value. For more information, see Best Practices for Handling Exceptions http://msdn.microsoft.com/en-us/library/seyhszts.aspx.
If the event is truly exceptional and is an error (such as an unexpected end-of-file), using exception handling is better because less code is executed in the normal case. If the event happens routinely, using the programmatic method to check for errors is better. In this case, if an exception occurs, the exception will take longer to handle.
System.Data.SqlClient.SqlException
System.IO.IOException
System.ArgumentException
System.NullReferenceException
System.OutOfMemoryException
System.OverflowException
System.DivideByZeroExecption
...
Two categories of exceptions exist under the base class Exception:
•The pre-defined common language runtime exception classes derived from SystemException.
•The user-defined application exception classes derived from ApplicationException.
User applications, not the common language runtime, throw custom exceptions derived from the ApplicationException class. The ApplicationException class differentiates between exceptions defined by applications versus exceptions defined by the system.
If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value. For more information, see Best Practices for Handling Exceptions http://msdn.microsoft.com/en-us/library/seyhszts.aspx.
If the event is truly exceptional and is an error (such as an unexpected end-of-file), using exception handling is better because less code is executed in the normal case. If the event happens routinely, using the programmatic method to check for errors is better. In this case, if an exception occurs, the exception will take longer to handle.
Linq to SQL
Linq to SQL
Stored Procedures using LINQ to SQL Classes
http://www.youtube.com/watch?v=t8rbLhnR8B4
Visual Studio 2008, Linq to SQL, C#, and WPF
Tutorial 1
http://www.youtube.com/watch?v=LEWZO4fO3hQ&feature=related
Tutorial 2
http://www.youtube.com/watch?v=d5B4cJ4yhB4
Tutorial 3
http://www.youtube.com/watch?v=BKrCrsfMn1c&feature=related
Tutorial 4 script for create table, constraints
http://www.youtube.com/watch?v=EyqeXsw-VGg
Tutorial 5
http://www.youtube.com/watch?v=E7abstYQxFk&feature=related
Tutorial 6 WPF user interface
http://www.youtube.com/watch?v=k4qOeVKf6g8
Tutorial 7 Add top menus
http://www.youtube.com/watch?v=2YvKrpycGxg&feature=related
Tutorial 8 Add sub menus
http://www.youtube.com/watch?v=K3grl_4ex-4&feature=related
Tutorial 9 Add Linq to SQL class
http://www.youtube.com/watch?v=IN01AvdEoig
Tutorial 10 Add other WPF windows
http://www.youtube.com/watch?v=G_fHht6J6xc&feature=related
Tutorial 11 ViewStudent GridView
http://www.youtube.com/watch?v=RBoZXO4FwKk&feature=related
Tutorial 12 Open ViewStudent window, exit main window
http://www.youtube.com/watch?v=mCbEhRJWWQ0&feature=related
Tutorial 13 Add student window
http://www.youtube.com/watch?v=RJoVNg7FIww&feature=related
Tutorial 14
http://www.youtube.com/watch?v=E_IZ6J7tML0&feature=related
Tutorial 15 Add validation
http://www.youtube.com/watch?v=4JyIBZ4JWME&feature=related
Tutorial 16 AddStudent method
http://www.youtube.com/watch?v=SyuXqdCDMiQ&feature=related
Tutorial 17
http://www.youtube.com/watch?v=fa_KOxs47yo&feature=related
Tutorial 18 Update student
http://www.youtube.com/watch?v=84l56lw-0R8&feature=related
Tutorial 19
http://www.youtube.com/watch?v=YiryqqN_ylw&feature=related
Tutorial 20 Update student method
http://www.youtube.com/watch?v=EVXD2x_Ia1o&feature=related
Tutorial 21 Delete student
http://www.youtube.com/watch?v=4snI4VerhqQ&feature=related
Stored Procedures using LINQ to SQL Classes
http://www.youtube.com/watch?v=t8rbLhnR8B4
Visual Studio 2008, Linq to SQL, C#, and WPF
Tutorial 1
http://www.youtube.com/watch?v=LEWZO4fO3hQ&feature=related
Tutorial 2
http://www.youtube.com/watch?v=d5B4cJ4yhB4
Tutorial 3
http://www.youtube.com/watch?v=BKrCrsfMn1c&feature=related
Tutorial 4 script for create table, constraints
http://www.youtube.com/watch?v=EyqeXsw-VGg
Tutorial 5
http://www.youtube.com/watch?v=E7abstYQxFk&feature=related
Tutorial 6 WPF user interface
http://www.youtube.com/watch?v=k4qOeVKf6g8
Tutorial 7 Add top menus
http://www.youtube.com/watch?v=2YvKrpycGxg&feature=related
Tutorial 8 Add sub menus
http://www.youtube.com/watch?v=K3grl_4ex-4&feature=related
Tutorial 9 Add Linq to SQL class
http://www.youtube.com/watch?v=IN01AvdEoig
Tutorial 10 Add other WPF windows
http://www.youtube.com/watch?v=G_fHht6J6xc&feature=related
Tutorial 11 ViewStudent GridView
http://www.youtube.com/watch?v=RBoZXO4FwKk&feature=related
Tutorial 12 Open ViewStudent window, exit main window
http://www.youtube.com/watch?v=mCbEhRJWWQ0&feature=related
Tutorial 13 Add student window
http://www.youtube.com/watch?v=RJoVNg7FIww&feature=related
Tutorial 14
http://www.youtube.com/watch?v=E_IZ6J7tML0&feature=related
Tutorial 15 Add validation
http://www.youtube.com/watch?v=4JyIBZ4JWME&feature=related
Tutorial 16 AddStudent method
http://www.youtube.com/watch?v=SyuXqdCDMiQ&feature=related
Tutorial 17
http://www.youtube.com/watch?v=fa_KOxs47yo&feature=related
Tutorial 18 Update student
http://www.youtube.com/watch?v=84l56lw-0R8&feature=related
Tutorial 19
http://www.youtube.com/watch?v=YiryqqN_ylw&feature=related
Tutorial 20 Update student method
http://www.youtube.com/watch?v=EVXD2x_Ia1o&feature=related
Tutorial 21 Delete student
http://www.youtube.com/watch?v=4snI4VerhqQ&feature=related
2010年7月19日星期一
Automating Visual Studio 2008
http://www.geekzone.co.nz/vs2008/6324
Efficient Navigation:
Visual Studio’s Code Editor provides efficient means to navigate around large files (using collapsible code blocks), large projects (using Bookmarks) that contain large numbers of classes and/or properties (using Object Explorer) as well as solutions that contain numerous projects (using Solution Explorer).
Code Creation:
In addition to UI designers, Visual Studio provider database schema designers (to graphically create and design database schemas as well as queries), a class designer (to graphically develop or document classes and their interactions), and a mapping designer (to graphically design the mapping between database schemas and the code entities that encapsulate the data).
Code Refactoring:
Beginning with VS2005, several refactoring tools are built directly into the IDE, which are accessible from the Code Editor’s context menu, or the main menu’s Refactor menu (which is only visible when the Code Editor has focus).
The refactoring tools offered are sparse, but helpful:
o Extract Method: Defines a new method, based on a selection of code statements.
o Encapsulate Field: Turns a public field into a private field, wrapping it with a public property.
o Extract Interface: Defines a new interface based on the current class’ public properties and methods.
o Reorder Parameters: Provides a way to reorder member parameters, as well as the arguments of all references to it throughout a project.
o Remove Parameters: Removes a member’s parameter, and the argument from of all references to it throughout a project.
o Rename: This allows you to rename a code token (method, field, etc.), and all references to it throughout a project.
o Promote Local Variable to Parameter: Moves a local variable to the parameter set of the defining method.
Efficient Navigation:
Visual Studio’s Code Editor provides efficient means to navigate around large files (using collapsible code blocks), large projects (using Bookmarks) that contain large numbers of classes and/or properties (using Object Explorer) as well as solutions that contain numerous projects (using Solution Explorer).
Code Creation:
In addition to UI designers, Visual Studio provider database schema designers (to graphically create and design database schemas as well as queries), a class designer (to graphically develop or document classes and their interactions), and a mapping designer (to graphically design the mapping between database schemas and the code entities that encapsulate the data).
Code Refactoring:
Beginning with VS2005, several refactoring tools are built directly into the IDE, which are accessible from the Code Editor’s context menu, or the main menu’s Refactor menu (which is only visible when the Code Editor has focus).
The refactoring tools offered are sparse, but helpful:
o Extract Method: Defines a new method, based on a selection of code statements.
o Encapsulate Field: Turns a public field into a private field, wrapping it with a public property.
o Extract Interface: Defines a new interface based on the current class’ public properties and methods.
o Reorder Parameters: Provides a way to reorder member parameters, as well as the arguments of all references to it throughout a project.
o Remove Parameters: Removes a member’s parameter, and the argument from of all references to it throughout a project.
o Rename: This allows you to rename a code token (method, field, etc.), and all references to it throughout a project.
o Promote Local Variable to Parameter: Moves a local variable to the parameter set of the defining method.
How to debug in Visual Studio
JavaScript Debugging in Visual Studio 2008
http://www.asp.net/aspnet-35/videos/javascript-debugging-in-visual-studio-2008
How Do I: Learn Tips and Tricks for Debugging in Visual Studio?
http://www.youtube.com/watch?v=4uyDBM-qTkk&feature=related
Visual Studio Debugging Tutorial
http://dotnetperls.com/debugging-1
It has many more options, including Call Stack, Command Window, Exceptions, and Autos. You can configure breakpoints to simply write messages to the console, or to keep counts of how many times they are hit. This is great for performance testing.
Here we note that the .NET Framework provides a variety of useful methods in the Debug class that can be used to hard-code debugging facilities in your programs. Some methods that you can use are Debug.Write and Debug.Assert. The benefit to these methods over the Console methods is that they are removed in Release builds of your application. You can find more details on these methods.
How to trace and debug in Visual C#
http://support.microsoft.com/kb/815788
You can also use the Trace class to produce messages that monitor the execution of an application. The Trace and Debug classes share most of the same methods to produce output, including the following:
WriteLine
WriteLineIf
Indent
Unindent
Assert
Flush
a Release Solution Configuration project only generates output from a Trace class. The Release Solution Configuration project ignores any Debug class method invocations.
To display the content of selected variables, use the Debug.WriteLine method.
Use the Assert method of the Debug class so that the Output window displays the message only if a specified condition evaluates to false.
Basic Debugging Features In Visual Studio 2005
http://odetocode.com/Articles/425.aspx
Another way to halt execution of a program is to ask the debugger to break when an exception occurs. By default, the debugger will only break if the exception goes unhandled, but this behavior is configurable. Select Exceptions from the Debug menu and you’ll see a tree display of all possible exceptions alongside checkboxes to indicate if the debugger should break when an exception “is thrown”, or only break if the exception is “user-unhandled”.
Breaking on exceptions can be useful when you are trying to track down an exception that occurs, but have not determined under what condition the exception occurs, or where the exception occurs.
DataTips are a transient display of information – once your mouse leaves the DataTip area the DataTip display will disappear.
A Watch Window will display an object’s state until you explicitly remove the object from the window.
The locals window will automatically display all local variables in the current block of code. If you are inside of a method, the locals window will display the method parameters and locally defined variables.
The Autos window (Debug -> Windows -> Autos) will display variables and expressions from the current line of code, and the preceding line of code.
A visualizer is a new way to view data in Visual Studio 2005. Some dataypes are too complex to display in a DataTip or watch window. For example, a DataSet is a tremendously complex and hierarchical object. Trying to drill into the 5th column of the 10th row of the 2nd table of a DataSet is cumbersome. Fortunately, a Visualizer exists for DataSet objects that will display the data in a more natural environment, namely an editable data grid.
Whenever a magnifying glass appears in a DataTip or watch window there is a visualizer available for the object. Double click on the magnifying glass to use the default visualizer. If multiple visualizers are available, you can click on the drop down chevron next to the magnifying glass and select which visualizer you’d like to use. For instance, a string will have three visualizers available: a text visualizer, an HTML visualizer, and an XML visualizer. There is also a visualizer for the DataSet and DataTable classes.
Improved Debugging with Visual Studio 2005's Debugger Visualizers
http://aspnet.4guysfromrolla.com/articles/011806-1.aspx
Visual Studio 2005 ships with four visualizers, a DataSet visualizer, which shows the contents of a DataSet in a grid, and three text-based visualizers: one for text, one for XML, and one for HTML. The screenshot below shows the XML Visualizer in action, which provides a much more readable view of the XML than simply squishing it all on one line.
Immediate and Command window in Visual Studio
http://dotnetdud.wordpress.com/2007/12/25/immediate-and-command-window-in-visual-studio/
The Command window is used to execute commands or aliases directly in the Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window
The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging. To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate.
It also includes a seemingly very complete list of commands and aliases that you can execute (for VS 2005 at least) - from either window, as far as I understand. Once of the nice features is that you can switch between the two windows simply by executing the cmd and immed commands.
In addition, see also the MSDN pages on the Command Window and the Immediate Window.
http://www.asp.net/aspnet-35/videos/javascript-debugging-in-visual-studio-2008
How Do I: Learn Tips and Tricks for Debugging in Visual Studio?
http://www.youtube.com/watch?v=4uyDBM-qTkk&feature=related
Visual Studio Debugging Tutorial
http://dotnetperls.com/debugging-1
It has many more options, including Call Stack, Command Window, Exceptions, and Autos. You can configure breakpoints to simply write messages to the console, or to keep counts of how many times they are hit. This is great for performance testing.
Here we note that the .NET Framework provides a variety of useful methods in the Debug class that can be used to hard-code debugging facilities in your programs. Some methods that you can use are Debug.Write and Debug.Assert. The benefit to these methods over the Console methods is that they are removed in Release builds of your application. You can find more details on these methods.
How to trace and debug in Visual C#
http://support.microsoft.com/kb/815788
You can also use the Trace class to produce messages that monitor the execution of an application. The Trace and Debug classes share most of the same methods to produce output, including the following:
WriteLine
WriteLineIf
Indent
Unindent
Assert
Flush
a Release Solution Configuration project only generates output from a Trace class. The Release Solution Configuration project ignores any Debug class method invocations.
To display the content of selected variables, use the Debug.WriteLine method.
Use the Assert method of the Debug class so that the Output window displays the message only if a specified condition evaluates to false.
Basic Debugging Features In Visual Studio 2005
http://odetocode.com/Articles/425.aspx
Another way to halt execution of a program is to ask the debugger to break when an exception occurs. By default, the debugger will only break if the exception goes unhandled, but this behavior is configurable. Select Exceptions from the Debug menu and you’ll see a tree display of all possible exceptions alongside checkboxes to indicate if the debugger should break when an exception “is thrown”, or only break if the exception is “user-unhandled”.
Breaking on exceptions can be useful when you are trying to track down an exception that occurs, but have not determined under what condition the exception occurs, or where the exception occurs.
DataTips are a transient display of information – once your mouse leaves the DataTip area the DataTip display will disappear.
A Watch Window will display an object’s state until you explicitly remove the object from the window.
The locals window will automatically display all local variables in the current block of code. If you are inside of a method, the locals window will display the method parameters and locally defined variables.
The Autos window (Debug -> Windows -> Autos) will display variables and expressions from the current line of code, and the preceding line of code.
A visualizer is a new way to view data in Visual Studio 2005. Some dataypes are too complex to display in a DataTip or watch window. For example, a DataSet is a tremendously complex and hierarchical object. Trying to drill into the 5th column of the 10th row of the 2nd table of a DataSet is cumbersome. Fortunately, a Visualizer exists for DataSet objects that will display the data in a more natural environment, namely an editable data grid.
Whenever a magnifying glass appears in a DataTip or watch window there is a visualizer available for the object. Double click on the magnifying glass to use the default visualizer. If multiple visualizers are available, you can click on the drop down chevron next to the magnifying glass and select which visualizer you’d like to use. For instance, a string will have three visualizers available: a text visualizer, an HTML visualizer, and an XML visualizer. There is also a visualizer for the DataSet and DataTable classes.
Improved Debugging with Visual Studio 2005's Debugger Visualizers
http://aspnet.4guysfromrolla.com/articles/011806-1.aspx
Visual Studio 2005 ships with four visualizers, a DataSet visualizer, which shows the contents of a DataSet in a grid, and three text-based visualizers: one for text, one for XML, and one for HTML. The screenshot below shows the XML Visualizer in action, which provides a much more readable view of the XML than simply squishing it all on one line.
Immediate and Command window in Visual Studio
http://dotnetdud.wordpress.com/2007/12/25/immediate-and-command-window-in-visual-studio/
The Command window is used to execute commands or aliases directly in the Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window
The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging. To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate.
It also includes a seemingly very complete list of commands and aliases that you can execute (for VS 2005 at least) - from either window, as far as I understand. Once of the nice features is that you can switch between the two windows simply by executing the cmd and immed commands.
In addition, see also the MSDN pages on the Command Window and the Immediate Window.
TDD & Unit Test
TDD Tests are not Unit Tests
http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx
Unit testing with Visual Studio 2008
http://www.geekzone.co.nz/vs2008/4819
A Unit Testing Walkthrough with Visual Studio Team Test
http://msdn.microsoft.com/en-us/library/ms379625(VS.80).aspx
The first noteworthy characteristic of Listing 6 is the addition of the DataSourceAttribute in which the connection string, table name, and access order are specified. In this listing we use a database file name to identify the database. The advantage of this is that the file will travel with the test project, assuming it is updated to be a relative path.
The second important characteristic is the TestContext.DataRow calls. TestContext is a property that the generator provided when we ran the Create Tests wizard. The property is automatically assigned by the test execution engine at runtime so that within a test we can access data associated with the test context, As Figure 7 shows, the TestContext provides data such as the TestDirectory and TestName, along with methods such as BeginTimer() and EndTimer(). What is most significant for the ChangePasswordTest() method is the DataRow property. Because the ChangePasswordTest() method is decorated with DataSourceAttribute, it will be called once for each record returned from the table specified by the attribute. This enables the test code to use the data within an executing test and have the test repeat for each record inserted into the LogonInfoTest table. If the table contains four records, then the test will be executed four separate times.
http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx
Unit testing with Visual Studio 2008
http://www.geekzone.co.nz/vs2008/4819
A Unit Testing Walkthrough with Visual Studio Team Test
http://msdn.microsoft.com/en-us/library/ms379625(VS.80).aspx
The first noteworthy characteristic of Listing 6 is the addition of the DataSourceAttribute in which the connection string, table name, and access order are specified. In this listing we use a database file name to identify the database. The advantage of this is that the file will travel with the test project, assuming it is updated to be a relative path.
The second important characteristic is the TestContext.DataRow calls. TestContext is a property that the generator provided when we ran the Create Tests wizard. The property is automatically assigned by the test execution engine at runtime so that within a test we can access data associated with the test context, As Figure 7 shows, the TestContext provides data such as the TestDirectory and TestName, along with methods such as BeginTimer() and EndTimer(). What is most significant for the ChangePasswordTest() method is the DataRow property. Because the ChangePasswordTest() method is decorated with DataSourceAttribute, it will be called once for each record returned from the table specified by the attribute. This enables the test code to use the data within an executing test and have the test repeat for each record inserted into the LogonInfoTest table. If the table contains four records, then the test will be executed four separate times.
2010年7月16日星期五
Differentiate logical and physical database?
http://wiki.answers.com/Q/Differentiate_logical_and_physical_database
After all business requirements have been gathered for a proposed database, they must be modeled. Models are created to visually represent the proposed database so that business requirements can easily be associated with database objects to ensure that all requirements have been completely and accurately gathered. Different types of diagrams are typically produced to illustrate the business processes, rules, entities, and organizational units that have been identified. These diagrams often include entity relationship diagrams, process flow diagrams, and server model diagrams. An entity relationship diagram (ERD) represents the entities, or groups of information, and their relationships maintained for a business. Process flow diagrams represent business processes and the flow of data between different processes and entities that have been defined. Server model diagrams represent a detailed picture of the database as being transformed from the business model into a relational database with tables, columns, and constraints. Basically, data modeling serves as a link between business needs and system requirements.
Two types of data modeling are as follows:
•Logical modeling
•Physical modeling
If you are going to be working with databases, then it is important to understand the difference between logical and physical modeling, and how they relate to one another. Logical and physical modeling are described in more detail in the following subsections.
Logical Modeling
Logical modeling deals with gathering business requirements and converting those requirements into a model. The logical model revolves around the needs of the business, not the database, although the needs of the business are used to establish the needs of the database. Logical modeling involves gathering information about business processes, business entities (categories of data), and organizational units. After this information is gathered, diagrams and reports are produced including entity relationship diagrams, business process diagrams, and eventually process flow diagrams. The diagrams produced should show the processes and data that exists, as well as the relationships between business processes and data. Logical modeling should accurately render a visual representation of the activities and data relevant to a particular business.
The diagrams and documentation generated during logical modeling is used to determine whether the requirements of the business have been completely gathered. Management, developers, and end users alike review these diagrams and documentation to determine if more work is required before physical modeling commences.
Typical deliverables of logical modeling include
•Entity relationship diagrams
An Entity Relationship Diagram is also referred to as an analysis ERD. The point of the initial ERD is to provide the development team with a picture of the different categories of data for the business, as well as how these categories of data are related to one another.
•Business process diagrams
The process model illustrates all the parent and child processes that are performed by individuals within a company. The process model gives the development team an idea of how data moves within the organization. Because process models illustrate the activities of individuals in the company, the process model can be used to determine how a database application interface is design.

Other business process sample can be found at:
http://content.usa.visual-paradigm.com/media/documents/bpva20ug/html/Ch06_Business_Process_Diagram_Samples/Ch06_Business_Process_Diagram_Samples.html
•User feedback documentation
Physical Modeling
Physical modeling involves the actual design of a database according to the requirements that were established during logical modeling. Logical modeling mainly involves gathering the requirements of the business, with the latter part of logical modeling directed toward the goals and requirements of the database. Physical modeling deals with the conversion of the logical, or business model, into a relational database model. When physical modeling occurs, objects are being defined at the schema level. A schema is a group of related objects in a database. A database design effort is normally associated with one schema.
During physical modeling, objects such as tables and columns are created based on entities and attributes that were defined during logical modeling. Constraints are also defined, including primary keys, foreign keys, other unique keys, and check constraints. Views can be created from database tables to summarize data or to simply provide the user with another perspective of certain data. Other objects such as indexes and snapshots can also be defined during physical modeling. Physical modeling is when all the pieces come together to complete the process of defining a database for a business.
Physical modeling is database software specific, meaning that the objects defined during physical modeling can vary depending on the relational database software being used. For example, most relational database systems have variations with the way data types are represented and the way data is stored, although basic data types are conceptually the same among different implementations. Additionally, some database systems have objects that are not available in other database systems.
Typical deliverables of physical modeling include the following:
•Server model diagrams
The server model diagram shows tables, columns, and relationships within a database.
•User feedback documentation Database design documentation
Conclusion
Understanding the difference between logical and physical modeling will help you build better organized and more effective database systems.
After all business requirements have been gathered for a proposed database, they must be modeled. Models are created to visually represent the proposed database so that business requirements can easily be associated with database objects to ensure that all requirements have been completely and accurately gathered. Different types of diagrams are typically produced to illustrate the business processes, rules, entities, and organizational units that have been identified. These diagrams often include entity relationship diagrams, process flow diagrams, and server model diagrams. An entity relationship diagram (ERD) represents the entities, or groups of information, and their relationships maintained for a business. Process flow diagrams represent business processes and the flow of data between different processes and entities that have been defined. Server model diagrams represent a detailed picture of the database as being transformed from the business model into a relational database with tables, columns, and constraints. Basically, data modeling serves as a link between business needs and system requirements.
Two types of data modeling are as follows:
•Logical modeling
•Physical modeling
If you are going to be working with databases, then it is important to understand the difference between logical and physical modeling, and how they relate to one another. Logical and physical modeling are described in more detail in the following subsections.
Logical Modeling
Logical modeling deals with gathering business requirements and converting those requirements into a model. The logical model revolves around the needs of the business, not the database, although the needs of the business are used to establish the needs of the database. Logical modeling involves gathering information about business processes, business entities (categories of data), and organizational units. After this information is gathered, diagrams and reports are produced including entity relationship diagrams, business process diagrams, and eventually process flow diagrams. The diagrams produced should show the processes and data that exists, as well as the relationships between business processes and data. Logical modeling should accurately render a visual representation of the activities and data relevant to a particular business.
The diagrams and documentation generated during logical modeling is used to determine whether the requirements of the business have been completely gathered. Management, developers, and end users alike review these diagrams and documentation to determine if more work is required before physical modeling commences.
Typical deliverables of logical modeling include
•Entity relationship diagrams
An Entity Relationship Diagram is also referred to as an analysis ERD. The point of the initial ERD is to provide the development team with a picture of the different categories of data for the business, as well as how these categories of data are related to one another.

•Business process diagrams
The process model illustrates all the parent and child processes that are performed by individuals within a company. The process model gives the development team an idea of how data moves within the organization. Because process models illustrate the activities of individuals in the company, the process model can be used to determine how a database application interface is design.

Other business process sample can be found at:
http://content.usa.visual-paradigm.com/media/documents/bpva20ug/html/Ch06_Business_Process_Diagram_Samples/Ch06_Business_Process_Diagram_Samples.html
•User feedback documentation
Physical Modeling
Physical modeling involves the actual design of a database according to the requirements that were established during logical modeling. Logical modeling mainly involves gathering the requirements of the business, with the latter part of logical modeling directed toward the goals and requirements of the database. Physical modeling deals with the conversion of the logical, or business model, into a relational database model. When physical modeling occurs, objects are being defined at the schema level. A schema is a group of related objects in a database. A database design effort is normally associated with one schema.
During physical modeling, objects such as tables and columns are created based on entities and attributes that were defined during logical modeling. Constraints are also defined, including primary keys, foreign keys, other unique keys, and check constraints. Views can be created from database tables to summarize data or to simply provide the user with another perspective of certain data. Other objects such as indexes and snapshots can also be defined during physical modeling. Physical modeling is when all the pieces come together to complete the process of defining a database for a business.
Physical modeling is database software specific, meaning that the objects defined during physical modeling can vary depending on the relational database software being used. For example, most relational database systems have variations with the way data types are represented and the way data is stored, although basic data types are conceptually the same among different implementations. Additionally, some database systems have objects that are not available in other database systems.
Typical deliverables of physical modeling include the following:
•Server model diagrams
The server model diagram shows tables, columns, and relationships within a database.
•User feedback documentation Database design documentation
Conclusion
Understanding the difference between logical and physical modeling will help you build better organized and more effective database systems.
DataView Sorting Filtering and DataBinding in ADO.NET 2.0 - Converting DataView to Table - ADO.NET Tutorials
http://davidhayden.com/blog/dave/archive/2006/02/11/2798.aspx
you will probably want to use the DataView Object in ADO.NET 2.0 for sorting and filtering a DataTable, because the DataView is bindable whereas the array of DataRows[] returned by the methods of the DataTable is not.
public DataView(DataTable table, string RowFilter, string Sort, DataViewRowState RowState)
Here is an example of using the full constructor to create a view from the Customers Table in the Northwind Database such that it only contains customers from a specific region ( SP ) and country ( Brazil ), sorted by ContactName, and including only current rows.
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(customers,"Region = 'SP' and Country = 'Brazil'", "ContactName", DataViewRowState.CurrentRows);
dataGridView1.DataSource = dv;
Now you don't have to use the full DataView Constructor, you can also specify individual properties based on your needs. For example, we can delete two records from the same Customers DataTable and then only view those deleted records in the DataGridView:
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(categories);
dv.Table.Rows[0].Delete();
dv.Table.Rows[1].Delete();
dv.RowStateFilter = DataViewRowState.Deleted;
dataGridView1.DataSource = dv;
you will probably want to use the DataView Object in ADO.NET 2.0 for sorting and filtering a DataTable, because the DataView is bindable whereas the array of DataRows[] returned by the methods of the DataTable is not.
public DataView(DataTable table, string RowFilter, string Sort, DataViewRowState RowState)
Here is an example of using the full constructor to create a view from the Customers Table in the Northwind Database such that it only contains customers from a specific region ( SP ) and country ( Brazil ), sorted by ContactName, and including only current rows.
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(customers,"Region = 'SP' and Country = 'Brazil'", "ContactName", DataViewRowState.CurrentRows);
dataGridView1.DataSource = dv;
Now you don't have to use the full DataView Constructor, you can also specify individual properties based on your needs. For example, we can delete two records from the same Customers DataTable and then only view those deleted records in the DataGridView:
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(categories);
dv.Table.Rows[0].Delete();
dv.Table.Rows[1].Delete();
dv.RowStateFilter = DataViewRowState.Deleted;
dataGridView1.DataSource = dv;
SCOPE_IDENTITY() vs. @@IDENTITY - Retrieving Identity for Most Recently Added Row in Table
http://davidhayden.com/blog/dave/archive/2006/01/17/2736.aspx
Although @@IDENTITY is one of those common practices in SQL Server 7, which does not have a SCOPE_IDENTITY() function, it is no longer the accepted way to get the identity of the most recently added row in a table in SQL Server 2000 and SQL Server 2005.
@@IDENTITY returns the most recently created identity for your current connection, not necessarily the identity for the recently added row in a table. You could have a situation where there is a trigger that inserts a new record in a Logs Table, for example, when your Stored Procedure or INSERT SQL Statement inserts a record in the Orders Table. If you use @@IDENTITY to retrieve the identity of the new order, you will actually get the identity of the record added into the Log Table and not the Orders Table, which will create a nasty, nasty bug in your data access layer.
To avoid the potential problems associated with someone adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your INSERT SQL Statement or Stored Procedure.
Although @@IDENTITY is one of those common practices in SQL Server 7, which does not have a SCOPE_IDENTITY() function, it is no longer the accepted way to get the identity of the most recently added row in a table in SQL Server 2000 and SQL Server 2005.
@@IDENTITY returns the most recently created identity for your current connection, not necessarily the identity for the recently added row in a table. You could have a situation where there is a trigger that inserts a new record in a Logs Table, for example, when your Stored Procedure or INSERT SQL Statement inserts a record in the Orders Table. If you use @@IDENTITY to retrieve the identity of the new order, you will actually get the identity of the record added into the Log Table and not the Orders Table, which will create a nasty, nasty bug in your data access layer.
To avoid the potential problems associated with someone adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your INSERT SQL Statement or Stored Procedure.
2010年7月15日星期四
ASP.NET Caching Features
http://msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspx
One of the most important factors in building high-performance, scalable Web applications is the ability to store items, whether data objects, pages, or parts of a page, in memory the initial time they are requested. You can store these items on the Web server or other software in the request stream, such as the proxy server or browser.
ASP.NET provides two types of caching: The first is called output caching, which allows you to store dynamic page and user control responses;
<%@ OutputCache Duration="60" VaryByParam="None" %>
The required VaryByParam attribute allows you to vary the cached output depending on GET query string or form POST parameters.
The second type of caching is traditional application data caching, which you can use to programmatically store arbitrary objects, such as data sets, to server memory.
Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath(\\myServer\myConfig.xml)));
Following code show how application responds when a data source or data set is not in the Cache:
DataView Source = (DataView)Cache["MyData1"];
if (Source == null) {
SqlConnection myConnection = new SqlConnection("server=localhost;Integrated Security=SSPI;database=pubs");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
Cache["MyData1"] = Source;
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
One of the most important factors in building high-performance, scalable Web applications is the ability to store items, whether data objects, pages, or parts of a page, in memory the initial time they are requested. You can store these items on the Web server or other software in the request stream, such as the proxy server or browser.
ASP.NET provides two types of caching: The first is called output caching, which allows you to store dynamic page and user control responses;
<%@ OutputCache Duration="60" VaryByParam="None" %>
The required VaryByParam attribute allows you to vary the cached output depending on GET query string or form POST parameters.
The second type of caching is traditional application data caching, which you can use to programmatically store arbitrary objects, such as data sets, to server memory.
Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath(\\myServer\myConfig.xml)));
Following code show how application responds when a data source or data set is not in the Cache:
DataView Source = (DataView)Cache["MyData1"];
if (Source == null) {
SqlConnection myConnection = new SqlConnection("server=localhost;Integrated Security=SSPI;database=pubs");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
Cache["MyData1"] = Source;
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
ASP.NET Cookies Overview
http://msdn.microsoft.com/en-us/library/ms178194.aspx
A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.
For example, if a user requests a page from your site and your application sends not just a page, but also a cookie containing the date and time, when the user's browser gets the page, the browser also gets the cookie, which it stores in a folder on the user's hard disk.
Later, if user requests a page from your site again, when the user enters the URL the browser looks on the local hard disk for a cookie associated with the URL. If the cookie exists, the browser sends the cookie to your site along with the page request. Your application can then determine the date and time that the user last visited the site. You might use the information to display a message to the user or check an expiration date.
Cookies are used for many purposes, all relating to helping the Web site remember users. For example, a site conducting a poll might use a cookie simply as a Boolean value to indicate whether a user's browser has already participated in voting so that the user cannot vote twice. A site that asks a user to log on might use a cookie to record that the user already logged on so that the user does not have to keep entering credentials.
If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser, the cookie is discarded. A non-persistent cookie like this is useful for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk.
Most browsers support cookies of up to 4096 bytes.
A cookie limitation that you might encounter is that users can set their browser to refuse cookies.you might have to avoid cookies altogether and use a different mechanism to store user-specific information. A common method for storing user information is session state, but session state depends on cookies, as explained later in the section "Cookies and Session State."
Before trying to get the value of a cookie, you should make sure that the cookie exists; if the cookie does not exist, you will get a NullReferenceException exception. Notice also that the HtmlEncode method was called to encode the contents of a cookie before displaying it in the page. This makes certain that a malicious user has not added executable script into the cookie.
A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.
For example, if a user requests a page from your site and your application sends not just a page, but also a cookie containing the date and time, when the user's browser gets the page, the browser also gets the cookie, which it stores in a folder on the user's hard disk.
Later, if user requests a page from your site again, when the user enters the URL the browser looks on the local hard disk for a cookie associated with the URL. If the cookie exists, the browser sends the cookie to your site along with the page request. Your application can then determine the date and time that the user last visited the site. You might use the information to display a message to the user or check an expiration date.
Cookies are used for many purposes, all relating to helping the Web site remember users. For example, a site conducting a poll might use a cookie simply as a Boolean value to indicate whether a user's browser has already participated in voting so that the user cannot vote twice. A site that asks a user to log on might use a cookie to record that the user already logged on so that the user does not have to keep entering credentials.
If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser, the cookie is discarded. A non-persistent cookie like this is useful for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk.
Most browsers support cookies of up to 4096 bytes.
A cookie limitation that you might encounter is that users can set their browser to refuse cookies.you might have to avoid cookies altogether and use a different mechanism to store user-specific information. A common method for storing user information is session state, but session state depends on cookies, as explained later in the section "Cookies and Session State."
Before trying to get the value of a cookie, you should make sure that the cookie exists; if the cookie does not exist, you will get a NullReferenceException exception. Notice also that the HtmlEncode method was called to encode the contents of a cookie before displaying it in the page. This makes certain that a malicious user has not added executable script into the cookie.
ASP.NET Session State Overview
http://msdn.microsoft.com/en-us/library/ms972429.aspx
We can configure the ASP.NET session state as cookieless session state. Essentially this feature allows sites whose clients choose not to use cookies to take advantage of ASP.NET session state.
This is done by modifying the URL with an ID that uniquely identifies the session:
http://localhost/(lit3py55t21z5v55vlm25s55)/Application/SessionState.aspx
ASP.NET will modify relative links found within the page and embed this ID. Thus, as long as the user follows the path of links the site provides, session state can be maintained. However, if the end user re-writes the URL, the session state instance will most likely be lost.
We can configure the ASP.NET session state as cookieless session state. Essentially this feature allows sites whose clients choose not to use cookies to take advantage of ASP.NET session state.
This is done by modifying the URL with an ID that uniquely identifies the session:
http://localhost/(lit3py55t21z5v55vlm25s55)/Application/SessionState.aspx
ASP.NET will modify relative links found within the page and embed this ID. Thus, as long as the user follows the path of links the site provides, session state can be maintained. However, if the end user re-writes the URL, the session state instance will most likely be lost.
TRANSACTION ISOLATION LEVEL
SET TRANSACTION ISOLATION LEVEL
{ READ UNCOMMITTED
| READ COMMITTED
| REPEATABLE READ
| SNAPSHOT
| SERIALIZABLE
}
[ ; ]
READ UNCOMMITTED
Specifies that statements can read rows that have been modified by other transactions but not yet committed.
READ COMMITTED
Specifies that statements cannot read data that has been modified but not committed by other transactions. This prevents dirty reads.
REPEATABLE READ
Specifies that statements cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes.
SNAPSHOT
Specifies that data read by any statement in a transaction will be the transactionally consistent version of the data that existed at the start of the transaction. Data modifications made by other transactions after the start of the current transaction are not visible to statements executing in the current transaction.
SERIALIZABLE
Specifies the following:
1. Statements cannot read data that has been modified but not yet committed by other transactions.
2. No other transactions can modify data that has been read by the current transaction until the current transaction completes.
3. Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes.
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN TRANSACTION;
...
COMMIT TRANSACTION;
{ READ UNCOMMITTED
| READ COMMITTED
| REPEATABLE READ
| SNAPSHOT
| SERIALIZABLE
}
[ ; ]
READ UNCOMMITTED
Specifies that statements can read rows that have been modified by other transactions but not yet committed.
READ COMMITTED
Specifies that statements cannot read data that has been modified but not committed by other transactions. This prevents dirty reads.
REPEATABLE READ
Specifies that statements cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes.
SNAPSHOT
Specifies that data read by any statement in a transaction will be the transactionally consistent version of the data that existed at the start of the transaction. Data modifications made by other transactions after the start of the current transaction are not visible to statements executing in the current transaction.
SERIALIZABLE
Specifies the following:
1. Statements cannot read data that has been modified but not yet committed by other transactions.
2. No other transactions can modify data that has been read by the current transaction until the current transaction completes.
3. Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes.
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN TRANSACTION;
...
COMMIT TRANSACTION;
2010年7月14日星期三
2010年7月9日星期五
2010年6月30日星期三
ASP.NET and JQuery
http://channel9.msdn.com/pdc2008/PC31/
1. What is ASP.NET AJAH and ASP.NET AJAX? What is good about ASP.NET AJAX?
ASP.NET AJAH refers to the approach that pages are created on the server and updated through AJAX requests for HTML. It can be achieved using update panel to build pure server side application while adding AJAX functionality to it. You do not need to write javascript in the page.
ASP.NET AJAX refers to the approach that pages are created on the client and updated through Ajax requests for JSON. It is pure AJAX application. You only pass critical data you need from server to client to update the page, and you allow the client to render the UI.
ASP.NET AJAX is more fast than ASP.NET AJAH, because of the following reasons:
- no postback at all, just ajax call
- only passs data, so less bandwidth
- less work on the web server, database server, many work can be done in client side
2. What is Microsoft AJAX Framework?
Microsoft AJAX Framework is ASP.NET AJAX + jQuery
- ASP.NET AJAX can build pure client side components and controls
- ASP.NET AJAX can use Client Templates to arrange your data in page
- ASP.NET AJAX provides AJAX Control Toolkit which is set of server control with AJAX functionality. Microsoft has also released a client only verson.
- jQuery has good selectors syntax, grab element out from DOM.
- jQuery has good animation framework.
- jQuery has a huge number of Plugins. http://plugins.jquery.com/
One Plugin example: tablesorter can be downloaded from http://tablesorter.com/
3. How to add jQuery reference in ASP.NET page?
1. What is ASP.NET AJAH and ASP.NET AJAX? What is good about ASP.NET AJAX?
ASP.NET AJAH refers to the approach that pages are created on the server and updated through AJAX requests for HTML. It can be achieved using update panel to build pure server side application while adding AJAX functionality to it. You do not need to write javascript in the page.
ASP.NET AJAX refers to the approach that pages are created on the client and updated through Ajax requests for JSON. It is pure AJAX application. You only pass critical data you need from server to client to update the page, and you allow the client to render the UI.
ASP.NET AJAX is more fast than ASP.NET AJAH, because of the following reasons:
- no postback at all, just ajax call
- only passs data, so less bandwidth
- less work on the web server, database server, many work can be done in client side
2. What is Microsoft AJAX Framework?
Microsoft AJAX Framework is ASP.NET AJAX + jQuery

- ASP.NET AJAX can build pure client side components and controls
- ASP.NET AJAX can use Client Templates to arrange your data in page
- ASP.NET AJAX provides AJAX Control Toolkit which is set of server control with AJAX functionality. Microsoft has also released a client only verson.
- jQuery has good selectors syntax, grab element out from DOM.
- jQuery has good animation framework.
- jQuery has a huge number of Plugins. http://plugins.jquery.com/
One Plugin example: tablesorter can be downloaded from http://tablesorter.com/
3. How to add jQuery reference in ASP.NET page?
2010年6月29日星期二
Improve your jQuery Selectors: 5 Quick Tips (Jack Franklin)
http://www.thewebsqueeze.com/web-design-tutorials/improve-your-jquery-selectors-5-quick-tips.html
A Complete Guide to jQuery 1.4 Selector Expressions
http://blog.insicdesigns.com/2010/05/a-complete-guide-to-jquery-1-4-selector-expressions/
Google Code Playground
http://code.google.com/apis/ajax/playground/
Six Things Every jQuery Developer Must Know
http://live.visitmix.com/MIX10/Sessions/EX22
http://elijahmanor.com/webdevdotnet/post/Mix10-Session-6-Things-Every-jQuery-Developer-Must-Know.aspx
A Complete Guide to jQuery 1.4 Selector Expressions
http://blog.insicdesigns.com/2010/05/a-complete-guide-to-jquery-1-4-selector-expressions/
Google Code Playground
http://code.google.com/apis/ajax/playground/
Six Things Every jQuery Developer Must Know
http://live.visitmix.com/MIX10/Sessions/EX22
http://elijahmanor.com/webdevdotnet/post/Mix10-Session-6-Things-Every-jQuery-Developer-Must-Know.aspx
Open eyes and keep up with technical evolution in .Net
I will use this blog to add lists of good articles and their digest which I find useful and enlightening. But I know it is more important to think after reading, so I will ask myself what is the purpose of the technology/tool, what is the advantages and disadvantages, how is it compared to some other similar alternatives. I am hoping it will be an interesting experience to study new stuff. If you have the same passion in studying .Net technology, please come by and we can discuss together. You are more than welcomed to point out any mistake that I made. Let's go!
订阅:
评论 (Atom)

