Skip to main content

Posts

Showing posts from February, 2008

USEFUL T-SQL QUERIES

Introduction: In this article we will look at some of the basic T-SQL Queries. These T-SQL Queries are very commonly used in most of the applications and I would like to point out that how easily some of these task can be performed. Returning String Instead of NULL: Consider a situation in which your database table contains NULL and you don't want to return NULL but some message. Like suppose you have a Person table and a Phone Table and a person does not have a phone number so we can easily return a message saying "No Phone Number Found" instead of returning a NULL. SELECT P.Name, 'PhoneNumber' = CASE WHEN Ph.PhoneNumber IS NULL THEN 'No Phone Number Exists' ELSE Ph.PhoneNumber END FROM tblPerson P, tblPhone Ph WHERE P.PersonID = Ph.PersonID The heart and soul of this simple query is the CASE Statement where we check that if the field is NULL or not. If the field is NULL we just replace it

Transferring Data Using SqlBulkCopy Class

Introduction : Transferring data from one source to another is a common practice in software development . This operation is preformed in many different scenarios which includes migration of the old system to the new system, backing up the data and collecting data from different publishers. ASP.NET 2.0 includes the SqlBulkCopy class that helps to copy the data from different data sources to SQL SERVER database . In this article I will demonstrate the different aspects of the SqlBulkCopy class. Database Design: The database design is pretty simple as it is based on the Products table in the Northwind database. I have created three more tables in the Northwind database. Check out the database diagram below to have better idea. The Products_Archive and Products_Latest have the same schema as the Products table while the Products_TopSelling table is different. I will explain the purpose of Products_TopSelling table later in this

How to convert a string to proper case

To convert a string to proper case we will have to use the System.Globalization namespace. To do this we will use the following code. string myString = "VikRAM’s WebSite HaVinG a post oN pRoper cAsE"; TextInfo TI = new CultureInfo("en-US",false).TextInfo; Response.Write (TI.ToTitleCase( myString )); [Note: Generally, title casing converts the first character of a word to uppercase and converts the rest of the letters to lowercase.]

Sending Email asynchronously in Asp.Net 2.0

Another of the new feature in asp.net 2.0 is the support to send emails asynchronously. This is a very important feature. With the help of this feature you don’t need to wait for the email to be sent before performing other tasks in the page. But instead these tasks can be performed while the mail is being sent asynchronously. To send Emails asynchronously we need to wire up a sendComplete event, create a send complete event and then call the sendAsync event. To do this first create an object and assign it the mail object. We can access this object in the call back. object userState = mail; Now we need to wire up the event when the async send is complete. smtp.SendCompleted += new SendCompletedEventHandler(SmtpClient_OnCompleted); Now start the asynchronous call smtp.SendAsync( mail, userState ); We have to write the wired-up method that will be invoked when the send is complete. public static void SmtpClient_OnCompleted(object sender, AsyncCompletedEventArgs e)

Registering the user control and custom control in the web.config

In asp.Net 1.X we had to import and use both customs server controls and user control on a page by adding the @Register directives to the top of the page. Once registered developers could then declare these controls anywhere on the page using the tag prefix and tag names configured in the @Register directive. This is fine but if we have too many user controls across the sites (and that too ascx files) then it can be painful to manage across the site. The control declaration is much cleaner and easier to manage in Asp.Net 2.0. Instead of duplicating them on all your pages, just declare them once within the new pages->controls section with the web.config file of your application The controls need to be added in the controls tag inside the pages tag which will be inside the system.web tag. An important this to note here is to use the ~ path as the user control can be used anywhere in the site. The “~” will resolve the control from the root of the web site. O