i was bit confused on SQL Server 2005 versions and also i have couple of mails in my inbox about SQL Server 2005 versions and features.
There are SQL Server 2005 features....
Enterprise Edition
Standard Edition
Workgroup Edition
Developer Edition
Express Edition
Mobile Edition
Everywhere Edition (CTP)
Keep watching for more information
Wednesday, April 30, 2008
SQL Server Versions 2005
Tuesday, April 29, 2008
Designing and creating a database
SQL Server 2005 stores your database information in two types of files: one or more database files and one or more transaction log files. As a database administrator (DBA), it is your duty to design and create databases to store user data and other objects. As part of your role as a database creator, you must decide how large to make these database files and what type of growth characteristics they should have, as well as their physical placement on your system.
In this article, you will get to know where to create a database and then put the data and log files.
First, you must decide where to put the data and log files.
Guidelines to Use
Data and log files should be on separate physical drives so that, in case of a disaster, you have a better chance of recovering all data.
Transaction logs are best placed on a RAID-1 array because this has the fastest sequential write speed.
Data files are best placed on a RAID-5 array because they have faster read speed than other RAID-arrays.
If you have access to a RAID-10 array, you can place data and log files on it because it has all the advantages of RAID-1 and RAID-5.
Next, you must decide how big your files should be. Data files are broken down into 8KB pages and 64KB extents (eight contiguous pages). To figure out how big your database will need to be, you must figure out how big your tables will be.
You can do that using these steps
Calculate the space used by a single row of the table.
a. To do this, add the storage requirements for each datatype in the table.
b. Add the null bitmap using this formula: null_bitmap = 2 + ((number of columns + 7) /8).
c. Calculate the space required for variable length columns using this formula: variable_datasize = 2 + (num_variable_columns X 2) + max_varchar_size.
d. Calculate the total row size using this formula: Row_Size = Fixed_Data_Size + Variable_Data_Size + Null_Bitmap + Row_Header.
NOTE: The row header is always 4 bytes
Calculate the number of rows that will fit on one page. Each page is 8,192 bytes with a header, so each page holds 8,096 bytes of data. Therefore, calculate the number of rows using this formula: 8096 ÷ (RowSize + 2).
Estimate the number of rows the table will hold. No formula exists to calculate this; you just need to have a good understanding of your data and user community.
Calculate the total number of pages that will be required to hold these rows. Use this formula: Total Number of Pages = Number of Rows in Table / Number of Rows Per Page.
Once you have decided where to put your files and how big they should be, follow these steps to create a database named Sales (you will be creating the files on a single drive for simplicity)
Start SQL Server Management Studio by selecting Start Programs Microsoft SQL Server 2005 Management Studio.
Connect to your default instance of SQL Server.
Expand your Databases folder.
Right-click either the Databases folder in the console tree or the white space in the right pane, and choose New Database from the context menu.
You should now see the General tab of the Database properties sheet. Enter the database name Sales, and leave the owner as
In the data files grid, in the Logical Name column, change the name of the primary data file to Sales_Data. Use the default location for the file, and make sure the initial size is 3.
Click the ellipsis button (the one with three periods) in the Autogrowth column for the Sales_Data file. In the dialog box that opens, check the Restricted File Growth radio button, and restrict the filegrowth to 20MB.
To add a secondary data file, click the Add button, and change the logical name of the new file to Sales_Data2. Here too use the default location for the file, and make sure the initial size is 3.
Restrict the filegrowth to a maximum of 20MB for Sales_Data2 by clicking the ellipsis button in the Autogrowth column.
Leave all of the defaults for the Sales_Log file.
Click OK when you are finished. You should now have a new Sales database.
You should see a database named Sales in SQL Server Management Studio.
Guidelines on Creating and Designing Database
Data and log files should be on separate physical drives so that, in case of a disaster, you have a better chance of recovering all data.
Transaction logs are best placed on a RAID-1 array because this has the fastest sequential write speed.
Data files are best placed on a RAID-5 array because they have faster read speed than other RAID-arrays.
If you have access to a RAID-10 array, you can place data and log files on it because it has all the advantages of RAID-1 and RAID-5.
Saturday, April 26, 2008
Validation control grouping
Validation control grouping has many advantages. First, it improves performance by instructing ASP.NET to perform validation on controls associated with a particular group. To accomplish this, ASP.NET 2.0 adds a ValidationGroup property to other controls that can cause postbacks such as buttons. This means that you can associate a Save button with a particular validation group. The Page class's Validate method is overloaded to accept a validation group name as an input parameter. When all of this is connected, the button instructs the page to perform server-side validation on only those controls in the specified group.
Another advantage of validation control is that it affords you the ability to restrict the information that is presented in a ValidationSummary control. Clearing the ValidationGroup property of the ValidationSummary control effectively associates the summary control with validation controls that also have a non-specified ValidationGroup property. Alternatively, specifying a value for the ValidationGroup property associates the ValidationSummary control with validation controls in the same group.
ValidationSummary Control
In addition to identifying specific fields with data entry problems, it is often useful to provide users with a summary of validation problems on a form. You can use the ValidationSummary control to provide that summary information to users. The ValidationSummary control is used to display the ErrorMessage property values from validation controls on the page when controls being validated are invalid.
Using the ValidationSummary control can improve usability by minimizing distracting and confusing text and by drawing the user's attention to a single location. Displaying specific data validation problems next to each field can consume a lot of screen real estate. In addition, it can cause shifts in screen layout, which leads to confusion. Using a ValidationSummary control concentrates more verbose information in a single location. Good examples of this include placing asterisks or exclamation points next to fields with validation problems.
CustomValidator Control
The controls described up to this point generally focuses on validating one or two fields based on specific, bounded parameters. Typical requirements, however, usually fall outside the capabilities of the intrinsic controls. In anticipation of this, the creators of ASP.NET made the CustomValidator control. The CustomValidator control provides you with an opportunity to create custom validation logic for situations requiring complex business rules validation.
Like other validation controls, the CustomValidator control exposes common properties such as ControlToValidate, Display, ErrorMessage, Text, and ValidationGroup. Also like other validation controls, the CustomValidator control supports both server-side and client-side validation. To associate custom server logic with the control, you must override the ServerValidate event. One of the parameters of the event handler for this event is an object of type ServerValidateEventArgs. Based on the results of the custom validation logic, you can set the IsValid property of the ServerValidateEventArgs object. For client-side validation, you must create a JavaScript function and reference that function using the ClientValidationFunction property of the CustomValidator control.
CompareValidator Control
Sometimes you need to compare the value in one field to that of another field instead of to some preset value, range, or pattern. In these situations, you can use the CompareValidator control. Like other validation controls, this control uses a ControlToValidate property. In addition, it adds a ControlToCompare property. This property gives you the ability to specify another control against which the value of the control in the ControlToValidate property is compared.
If you want to compare the control's value against a constant value, you can use the ValueToCompare property instead of the ControlToCompare property. If you set both properties, the ControlToCompare property takes precedence over the ValueToCompare property.
The default comparison operator for the CompareValidator control is equality. However, this is programmable through the Operator property. Valid operators are defined by the ValidationCompareOperator enumeration and include Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, and DataTypeCheck. The DataTypeCheck operator is the only unary operator among them. It is used to determine whether the data in the control identified by the ControlToValidate property is of a certain type. In fact, if you set the ControlToCompare and ValueToCompare properties, they are ignored if the operator type is set to DataTypeCheck. The DataTypeCheck operator uses the value of the Type property as a base for determining the acceptable data type. The Type property is set based on the ValidationDataType enumeration as described in the RangeValidator control previously mentioned.
RegularExpressionValidator Control
Regular expressions are an extremely powerful means of quickly parsing text. Regular expressions use an extensive pattern-matching notation to provide searching, replacing, and other text operations quickly and efficiently. The pattern-matching capabilities of regular expressions are of particular interest when using the RegularExpressionValidator control.
Regular-expression validation is generally used to ensure that specified data matches a predetermined pattern. For example, all e-mail addresses follow a common pattern. The regular expression used for comparison is specified with the ValidationExpression property. This property can contain any valid regular expression. Relying once again on the example of validating an e-mail address, you can use the following regular expression.
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
It is pretty obvious that the regular expression syntax is quite cryptic. Fortunately, there are libraries of regular expressions available. In fact, the RegularExpressionValidator control has some predefined regular expressions (including e-mail address). You can always, of course, write your own regular expressions for validation. Suppose, for example, you have a custom purchase order number format. You can use a regular expression to validate data in the purchase order number field against the pattern you define.
RangeValidator Control
Situations in which a value must fall within a certain range, rather than merely being specified, call for the RangeValidator control. This control allows you to ensure that a specified value is within acceptable limits, using a combination of properties including MaximumValue and MinimumValue. If either of these properties is blank, the control assumes no maximum or minimum (depending on which is blank).
The RangeValidator control allows you to validate the ranges of various data types. You are not restricted to numeric types. In fact, the RangeValidator control supports range validation of any data type described by the ValidationDataType enumeration. These include Currency, Date, Double, Integer, and String.
RequiredFieldValidator Control
The RequiredFieldValidator control is used to ensure that fields that must be populated with data are, indeed, populated with data. This control can be used with virtually any data entry controls, such as TextBox, DropDownList, and CheckBox. The RequiredFieldValidator control works by comparing the selected value of the control specified in the ControlToValidate property against an initial value that you specify. If you do not specify an initial value, an empty string is assumed.
This initial value against which comparisons are made is established using the InitialValue property. The default value is an empty string. However, you can set it to any value you like. Suppose, for example, you want to provide some assistance to users specifying dates by pre-filling the date field with MM/DD/YYYY. In this situation, you can set the InitialValue property of the associated RequiredFieldValidator control. This means that the user is still required to specify a value and cannot rely on the initial default value that you provide for guidance.
Difference between ISNULL() and COALESCE()
There is very slightly difference between the ISNULL and COALESCE functions.
Both the function Replaces the NULL value with the other specified replacement value but there is a very minor difference between them.
e.g. for ISNULL
DECLARE @var varchar(3)
SET @var = NULL
select ISNULL(@var,'abc')
The out put of this query is 'abc'.
e.g for COALESCE
DECLARE @var varchar(3)
SET @var = NULL
select COALESCE (@var,'abc')
The out put of this query is also 'abc'.
Now i am discussing the difference between them..
The difference is:
"The result of ISNULL() function always takes on the datatype of the first parameter (regardless of whether it is NULL or NOT NULL)
while for COALESCE works, it works like a CASE expression."
The difference between them will be more clear by this example.
DECLARE @var varchar(3)
SET @var = NULL
select ISNULL(@var,'abcdef')
The out put of this query is 'abc'. --as we mention the datatype of @var as varchar of size "3".
----
DECLARE @var varchar(3)
SET @var = NULL
select COALESCE (@var,'abcdef')
The out put of this query is 'abcdef'. -- Regardless the size of the @var.
difference between Server.Transfer and Response.Redirect
Response.Redirect involves a roundtrip to the server whereas Server.Transfer conserves server resources by avoiding the roundtrip. It just changes the focus of the webserver to a different page and transfers the page processing to a different page.
Response.Redirect can be used for both .aspx and html pages whereas Server.Transfer can be used only for .aspx pages.
Response.Redirect can be used to redirect a user to an external websites. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.
Response.Redirect changes the url in the browser. So they can be bookmarked. Whereas Server.Transfer retains the original url in the browser. It just replaces the contents of the previous page with the new one.
Wedb/Machine Config
Web.config files are used to apply configuration settings to a particular web application whereas machine.config file is used to apply configuration settings for all the websites on a web server.
Web.config files are located in the application's root directory or inside a folder situated in a lower hierarchy. The machine.config is located in the Windows directory Microsoft.Net\Framework\Version\CONFIG.
There can be multiple web.config files in an application nested at different hierarchies. However there can be only one machine.config file on a web server.
ASP.Net Interview Questions 4
What is a nested master page? How do you create them?
A Nested master page is a master page associated with another master page. To create a nested master page, set the MasterPageFile attribute of the @Master directive to the name of the .master file of the base master page.
What are Themes?
Themes are a collection of CSS files, .skin files, and images. They are text based style definitions and are very similar to CSS, in that they provide a common look and feel throughout the website.
What are skins?
A theme contains one or more skin files. A skin is simply a text file with a .skin extension and contains definition of styles applied to server controls in an ASP.NET page. For eg:
Defines a skin that will be applied to all buttons throughout to give it a consistent look and feel.
What is the difference between Skins and Css files?
Css is applied to HTML controls whereas skins are applied to server controls.
What is a User Control?
User controls are reusable controls, similar to web pages. They cannot be accessed directly.
Explain briefly the steps in creating a user control?
· Create a file with .ascx extension and place the @Control directive at top of the page.
· Included the user control in a Web Forms page using a @Register directive
What is a Custom Control?
Custom controls are compiled components that run on the server and that encapsulate user-interface and other related functionality into reusable packages. They can include all the design-time features of standard ASP.NET server controls, including full support for Visual Studio design features such as the Properties window, the visual designer, and the Toolbox.
What are the differences between user and custom controls?
User controls are easier to create in comparison to custom controls, however user controls can be less convenient to use in advanced scenarios.
User controls have limited support for consumers who use a visual design tool whereas custom controls have full visual design tool support for consumers.
A separate copy of the user control is required in each application that uses it whereas only a single copy of the custom control is required, in the global assembly cache, which makes maintenance easier.
A user control cannot be added to the Toolbox in Visual Studio whereas custom controls can be added to the Toolbox in Visual Studio.
User controls are good for static layout whereas custom controls are good for dynamic layout.
Where do you store your connection string information?
The connection string can be stored in configuration files (web.config).
ASP.Net Interview Questions 3
Explain the ASP.NET Page Directives?
Page directives configure the runtime environment that will execute the page. The complete list of directives is as follows:
@ Assembly - Links an assembly to the current page or user control declaratively.
@ Control - Defines control-specific attributes used by the ASP.NET page parser and compiler and can be included only in .ascx files (user controls).
@ Implements - Indicates that a page or user control implements a specified .NET Framework interface declaratively.
@ Import - Imports a namespace into a page or user control explicitly.
@ Master - Identifies a page as a master page and defines attributes used by the ASP.NET page parser and compiler and can be included only in .master files.
@ MasterType - Defines the class or virtual path used to type the Master property of a page.
@ OutputCache - Controls the output caching policies of a page or user control declaratively.
@ Page - Defines page-specific attributes used by the ASP.NET page parser and compiler and can be included only in .aspx files.
@ PreviousPageType - Creates a strongly typed reference to the source page from the target of a cross-page posting.
@ Reference - Links a page, user control, or COM control to the current page or user control declaratively.
@ Register - Associates aliases with namespaces and classes, which allow user controls and custom server controls to be rendered when included in a requested page or user control.
This list has been taken from here.
Explain the Validation Controls used in ASP.NET 2.0?
Validation controls allows you to validate a control against a set of rules. There are 6 different validation controls used in ASP.NET 2.0.
RequiredFieldValidator – Checks if the control is not empty when the form is submitted.
CompareValidator – Compares the value of one control to another using a comparison operator (equal, less than, greater than etc).
RangeValidator – Checks whether a value falls within a given range of number, date or string.
RegularExpressionValidator – Confirms that the value of a control matches a pattern defined by a regular expression. Eg: Email validation.
CustomValidator – Calls your own custom validation logic to perform validations that cannot be handled by the built in validators.
ValidationSummary – Show a summary of errors raised by each control on the page on a specific spot or in a message box.
How do you indentify that the page is post back?
By checking the IsPostBack property. If IsPostBack is True, the page has been posted back.
What are Master Pages?
Master pages is a template that is used to create web pages with a consistent layout throughout your application. Master Pages contains content placeholders to hold page specific content. When a page is requested, the contents of a Master page are merged with the content page, thereby giving a consistent layout.
How is a Master Page different from an ASP.NET page?
The MasterPage has a @Master top directive and contains ContentPlaceHolder server controls. It is quiet similar to an ASP.NET page.
How do you attach an exisiting page to a Master page?
By using the MasterPageFile attribute in the @Page directive and removing some markup.
How do you set the title of an ASP.NET page that is attached to a Master Page?
By using the Title property of the @Page directive in the content page. Eg:
<@Page MasterPageFile="Sample.master" Title="I hold content" %>
ASP.Net Interview Questions 2
What is ASP.NET?
Microsoft ASP.NET is a server side technology that enables programmers to build dynamic Web sites, web applications, and XML Web services. It is a part of the .NET based environment and is built on the Common Language Runtime (CLR) . So programmers can write ASP.NET code using any .NET compatible language.
What are the differences between ASP.NET 1.1 and ASP.NET 2.0?
A comparison chart containing the differences between ASP.NET 1.1 and ASP.NET 2.0 can be found over here.
Which is the latest version of ASP.NET? What were the previous versions released?
The latest version of ASP.NET is 2.0. There have been 3 versions of ASP.NET released as of date. They are as follows :
ASP.NET 1.0 – Released on January 16, 2002.
ASP.NET 1.1 – Released on April 24, 2003.
ASP.NET 2.0 – Released on November 7, 2005.
Additionally, ASP.NET 3.5 is tentatively to be released by the end of the 2007.
Explain the Event Life cycle of ASP.NET 2.0?
The events occur in the following sequence. Its best to turn on tracing() and track the flow of events :
PreInit – This event represents the entry point of the page life cycle. If you need to change the Master page or theme programmatically, then this would be the event to do so. Dynamic controls are created in this event.
Init – Each control in the control collection is initialized.
Init Complete* - Page is initialized and the process is completed.
PreLoad* - This event is called before the loading of the page is completed.
Load – This event is raised for the Page and then all child controls. The controls properties and view state can be accessed at this stage. This event indicates that the controls have been fully loaded.
LoadComplete* - This event signals indicates that the page has been loaded in the memory. It also marks the beginning of the rendering stage.
PreRender – If you need to make any final updates to the contents of the controls or the page, then use this event. It first fires for the page and then for all the controls.
PreRenderComplete* - Is called to explicitly state that the PreRender phase is completed.
SaveStateComplete* - In this event, the current state of the control is completely saved to the ViewState.
Unload – This event is typically used for closing files and database connections. At times, it is also used for logging some wrap-up tasks.
The events marked with * have been introduced in ASP.NET 2.0.
You have created an ASP.NET Application. How will you run it?
With ASP.NET 2.0, Visual Studio comes with an inbuilt ASP.NET Development Server to test your pages. It functions as a local Web server. The only limitation is that remote machines cannot access pages running on this local server. The second option is to deploy a Web application to a computer running IIS version 5 or 6 or 7.
Explain the AutoPostBack feature in ASP.NET?
AutoPostBack allows a control to automatically postback when an event is fired. For eg: If we have a Button control and want the event to be posted to the server for processing, we can set AutoPostBack = True on the button.
How do you disable AutoPostBack?
Hence the AutoPostBack can be disabled on an ASP.NET page by disabling AutoPostBack on all the controls of a page. AutoPostBack is caused by a control on the page.
What are the different code models available in ASP.NET 2.0?
There are 2 code models available in ASP.NET 2.0. One is the single-file page and the other one is the code behind page.
Which base class does the web form inherit from?
Page class in the System.Web.UI namespace.
ASP.Net Interview Questions 1
What is XHTML? Are ASP.NET Pages compliant with XHTML?
In simple words, XHTML is a stricter and cleaner version of HTML. XHTML stands for EXtensible Hypertext Markup Language and is a W3C Recommendation.
Yes, ASP.NET 2.0 Pages are XHTML compliant. However the freedom has been given to the user to include the appropriate document type declaration.
More info can be found at http://msdn2.microsoft.com/en-us/library/exc57y7e.aspx
Can I deploy the application without deploying the source code on the server?
Yes. You can obfuscate your code by using a new precompilation process called ‘precompilation for deployment’. You can use the aspnet_compiler.exe to precompile a site. This process builds each page in your web application into a single application DLL and some placeholder files. These files can then be deployed to the server.
You can also accomplish the same task using Visual Studio 2005 by using the Build->Publish menu.
Does ViewState affect performance? What is the ideal size of a ViewState? How can you compress a viewstate?
Viewstate stores the state of controls in HTML hidden fields. At times, this information can grow in size. This does affect the overall responsiveness of the page, thereby affecting performance. The ideal size of a viewstate should be not more than 25-30% of the page size.
Viewstate can be compressed to almost 50% of its size. .NET also provides the GZipStream or DeflateStream to compress viewstate.
IndexView
A clustered Index is a type of view in which we can create an Index.
We can create one clustured and many non-clustured index on view,but the first index created on a view must be a unique
We can not create a index on all the views.
A view must meet the following requirements before you can create a clustered index on it:
The ANSI_NULLS and QUOTED_IDENTIFIER options must have been set to ON when the CREATE VIEW statement was executed. The OBJECTPROPERTY function reports this for views through the ExecIsAnsiNullsOn or ExecIsQuotedIdentOn properties.
The ANSI_NULLS option must have been set to ON for the execution of all CREATE TABLE statements that create tables referenced by the view.
The view must not reference any other views, only base tables.
All base tables referenced by the view must be in the same database as the view and have the same owner as the view.
The view must be created with the SCHEMABINDING option. Schema binding binds the view to the schema of the underlying base tables.
User-defined functions referenced in the view must have been created with the SCHEMABINDING option.
Tables and user-defined functions must be referenced by two-part names in the view. One-part, three-part, and four-part names are not allowed.
All functions referenced by expressions in the view must be deterministic. The IsDeterministic property of the OBJECTPROPERTY function reports whether a user-defined function is deterministic or not.
SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
QUOTED_IDENTIFIER, ANSI_NULLS ON;
GO
--Create view with schemabinding.
CREATE VIEW test
WITH SCHEMABINDING
AS
SELECT SUM(UnitPrice) AS Revenue,
OrderDate, ProductID, COUNT_BIG(*) AS COUNT
FROM Sales.SalesOrderDetail AS od, Sales.SalesOrderHeader AS o
WHERE od.SalesOrderID = o.SalesOrderID
GROUP BY OrderDate, ProductID;
GO
--Create an index on the view.
CREATE UNIQUE CLUSTERED INDEX IDX_V1
ON Sales.vOrders (OrderDate, ProductID);
GO
Bulk Insert in SQL Server
Very often we come across a scenario where we need to execute same Insert or update commands with different values multiple times in one go. Say for example, show multiple records in updatable grid/tablular format allowing user to update them and then update them in database. Their are multiple ways to handle it and simplest being execute each DML command one after the other. The most resource consuming part of it is establishing connection for each DML command. Well, connection pooling helps a bit, but still one needs to request for connection from the connection pool. For details about connection pooling, refer to the article ADO.NET Connection Pooling at a Glance . Best solution in such a situation would be to establish the connection only once and perform multiple insert/update within it, and this is what is the target of this article. Let us see couple of mechanisms in which we can do this.
With ADO.NET 2.0 we got the programming interface for Bulk Copy which provides quite simple and straight forward mechanism to transfer the data from one SQL server instance to another, from one table to another, from DataTable to SQL Server 2005 database, from DataReader to SQL Server 2005 database and many more.
To start with It, first of all create a simple Person table as below in your database
CREATE TABLE Person
(
PersonId INT PRIMARY KEY,
PersonName VARCHAR(100)
)
SqlBulkCopy belongs to System.Data.SqlClient namespace and it is as simple as ADO.NET Command object when it comes to programming it. Let us see it working:
private void btnSQLBulkCopyInsert_Click(object sender, EventArgs e)
{
// Get the DataTable
DataTable dtInsertRows = GetDataTable();
using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString))
{
sbc.DestinationTableName = "Person";
// Number of records to be processed in one go
sbc.BatchSize = 2;
// Map the Source Column from DataTabel to the Destination Columns in SQL Server 2005 Person Table
sbc.ColumnMappings.Add("PersonId", "PersonId");
sbc.ColumnMappings.Add("PersonName", "PersonName");
// Number of records after which client has to be notified about its status
sbc.NotifyAfter = dtInsertRows.Rows.Count;
// Event that gets fired when NotifyAfter number of records are processed.
sbc.SqlRowsCopied+=new SqlRowsCopiedEventHandler(sbc_SqlRowsCopied);
// Finally write to server
sbc.WriteToServer(dtInsertRows);
sbc.Close();
}
}
void sbc_SqlRowsCopied(object sender, SqlRowsCopiedEventArgs e)
{
MessageBox.Show("Number of records affected : " + e.RowsCopied.ToString());
}
The code above is very simple and quite self explanatory.
check out below link
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx
for more information
Sunday, April 20, 2008
REVERSE String
There were couple of mails around in simple way how to reverse a string....
Public Function ReverseString(ByVal InputString As String) _
As String
Dim lLen As Long, lCtr As Long
Dim sChar As String
Dim sAns As String
lLen = Len(InputString)
For lCtr = lLen To 1 Step -1
sChar = Mid(InputString, lCtr, 1)
sAns = sAns & sChar
Next
ReverseString = sAns
End Function
Saturday, April 12, 2008
Log4net
After going through the log4net manual and adding some logging statements to my code, i must say that i am quite impressed with the overall design and ease of use of the framework. I am going to use log4net into production code now and i am also thinking about discontinuing the use of Microsoft Exception Management Application Block since i can get all that functionality using log4net.
Thursday, April 10, 2008
Validation Controls in ASP.NET
Several Validation Controls are provided with the ASP.Net framework. The great thing about these controls, is that they can be used with little or no programming. Naturally, there are many properties which need to be populated, but compared to the old Javascript way of programming form fields, it is much easier with ASP.Net
Name :
ControlToValidate="txtName"
Display="Dynamic"
ErrorMessage="Must have a value entered!"
Runat="server">
The property 'EnableClientScript' enables the validator to run on the client side, and not require a postback to the server. 'ControlToValidate' merely 'hooks-up' the validation control to a particular form field. In this case, we are using an ASP.Net Textbox Server control named 'txtName'. The 'Display' property is really valuable. If you choose 'Dynamic' as the property value, then, valuable real estate on the page is saved. It only shows, if it fires and displays the message. Without assigning it's value as 'Dynamic', the space needed for the message will be visually blank at all times. And of course, 'ErrorMessage' is exactly what you would think it is. It's the message that's actually displayed on the screen.
If nothing is entered into the textbox, when focus to the textbox is lost, it will fire (whether tabbing out of the textbox, or submitting the form).
Tuesday, April 8, 2008
Get Vs Post
Get and Post are methods used to send data to the server:
With the Get method, the browser appends the data onto
the URL. With the Post method, the data is sent
as "standard input."
Use GET:
- during development for debugging purposes (although in ASP.NET it's
also easy to see what has been sent through POST).
- if you want your visitors to be able to bookmark the submitted pages
- if you want to refer to submitted pages using hyperlinks
Use POST:
- for forms with password fields
- for large forms or forms with large text fields
Please note that web forms in ASP.NET use POST by default. It can be
changed into GET, but only for small forms. Web forms can post a lot
of data, especially when ViewState is involved.
Partial classes
This is a feature of 2005,when we have large and unwildly classes instead of writing all the methods in same program we will divide the class into number of programs with the same class name,these classes are preceeded with partial keyword,when we compile all this partial classes only one dll with the same class name will be created.
class with some 20 methods:
Example.cs
class classA{
m1( );
m2( );
.
.
.
m20( );
}
Apply partial concept:
Example1.cs
partial class classA
{
m1( );
m2( );
.
.
m8( );
}
example2.cs
partial class classA
{
m9( );
m10( );
.
.
m15( );
}
Example3.cs
partial class classA
{
m16( );
.
.
m20( );
}
if we compile Examle1.cs,Example2.cs,Example3.cs it will create only one dll
What is Silverlight
Silverlight is a new Web presentation technology that is created to run on a variety of platforms. It enables the creation of rich, visually stunning and interactive experiences that can run everywhere: within browsers and on multiple devices and desktop operating systems (such as the Apple Macintosh). In consistency with WPF (Windows Presentation Foundation), the presentation technology in Microsoft .NET Framework 3.0 (the Windows programming infrastructure), XAML (eXtensible Application Markup Language) is the foundation of the Silverlight presentation capability.
Keep watching there is something more on SilverLight....
What is Silverlight
Silverlight is a new Web presentation technology that is created to run on a variety of platforms. It enables the creation of rich, visually stunning and interactive experiences that can run everywhere: within browsers and on multiple devices and desktop operating systems (such as the Apple Macintosh). In consistency with WPF (Windows Presentation Foundation), the presentation technology in Microsoft .NET Framework 3.0 (the Windows programming infrastructure), XAML (eXtensible Application Markup Language) is the foundation of the Silverlight presentation capability.
Keep watching there is something more on SilverLight....
Monday, April 7, 2008
Page Life-cycle Stages Part 2
Load During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Validation During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
Postback event handling If the request is a postback, any event handlers are called.
Rendering Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.
Unload Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.
Page Life-cycle Stages Part 1
One of the Most famous questions in forum or in interview is explain about different page life cycle stages...
so finally here is the answer....
Page request The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled or whether a cached version of the page can be sent in response without running the page.
Start In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
Page initializationDuring page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Keep watching for more information...