Feed on
Posts
Comments
Introduction
Hi, you all people are aware of the browser Firefox. A simple and easy to use browser, you can say that Firefox is Simply an Awesome browser. Firefox provides you add-ons which you can integrate with Firefox to get more benefits and improve your surfing experience, if you’re a web developer then you must have all these add-ons which I am going to list below. All these add-ons, I used personally and got some benefits they helps me in many ways. As we know the Firefox is an Open-Source browser, that means you need not to pay anything for that, so all these add-ons are also free of cost. So download and use them. So let’s have a look of these cool add-ons.
 

clip_image001[4]

Clearing a cache is always needed for a web developer. Sometimes if you have done any updates in website then it will again and again continues to display the older contents from the cache of the browser, and de to which we thought may be we have done some mistake in code. But in actually it’s the game of cache. So to clear the cache you have to go the options of the browser and then we’ll clear the cache. But going to the options every time is a headache, so don’t worry your headache will be goes out with this cool add-on (Clear Cache Button). This add-on will add a Clear cache button in toolbar of your Firefox browser.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/1801

 

clip_image002[4]

ColorZilla basically a color picker tool for firefox, using this tool you can get the HEX and RGB code of the colors. This can only select the color inside the firefox window not outside that. This helps very much when on some website you sees a color and want use it, so this will help you to get the color code of the color which you can use in your web page code. You can find this tool after installing in Left side of the status bar.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/271

 

clip_image003[4]

This tool is very good downloader for firefox. This increases speed of your downloading file and download that fast. It provides many functionality like, pause, stop etc. I like this tool at least for firefox browser. You must have this tool if you’re having firefox installed in your system.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/201  

 

clip_image004[4]

Firesizer provides you the resolutions using which you can view your website in all resolutions. This is displayed in the status bar when you’ll install this in your browser.

https://addons.mozilla.org/en-US/firefox/addon/5792

 

clip_image005[4]

This is not very useful tool but still it’s a good tool if you want to know about website server, that where the website server is located in the world. Flagfox display the Flag of the country where the website server is located in the world.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/5791

 

clip_image006[4]

This is not necessary but it’s good to have this cool add-on, this will add the favicon of the websites before the search result in the search result of the Google. You can notice existence of this tool when you search anything in Google after installing it.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/4676

 

clip_image007[4]

This tool is a text highlighter of the text which you’re searching. Means when you click Ctrl+F then it will highlight all occurrence of the text you’re searching in the current page.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/4240

 

clip_image008[4]

McAfee site advisor advises you that which website is safe to visit or which is not. It advises you that it’s not safe to visit this website automatically by showing a small popup when you open any unsafe website. And when you search for anything in Google then it will also displays the safe and unsafe icon in the search result.

Get this from here: http://www.siteadvisor.com/download/ff.html

 

clip_image009[4]

This option is used to open the image in new window. Means when you click on any image on a website then there are two three options like save image, view image etc but not always you want to save all images, in firefox I used to view the image first if it suits my requirement then save it. But when we click view image then it opens the image in the same window, which diverts your mind, so it’s better to open that image in new tab and think about it later. So if you want to see this image in new tab then this is a very helpful tool. You can find this option in the Context menu (Right-Click menu) whenever you right click on any image in the browser.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/2248

 

clip_image010[4]

This add-on will restart all your firefox windows. You need not to go and close each and every window, you just need to click this menu “Quick Restart” and will automatically restart all your firefox browser windows.

When you install this add on then you can find this feature in File -> Restart Firefox OR you can use the shortcut key Ctrl+Alt+R

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/3559

 

clip_image011[4]

Sometimes you want that whatever windows you have opened now, you’ll get all these when you next starts the windows or firefox. This add-on is useful for web developers or software developer who, use to visit the chatting sites without his boss permission. Means if you are chatting and you knows that your boss is coming at your desk then you just save the session of firefox an close all your browser windows and when he gone from there then again start firefox and you’ll get all your windows as it is, but this is other side but normally this add-on helps very much, you just save session and shutdowns your windows, then when you next start your windows you can get all your firefox windows as it is.. [J] You can find this in (File -> Save Session & Exit) after installing this add-on.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/4199

 

clip_image012[4]

SEO firefox, an AWESOME tool which displays the SEO statistics for the website in the Google search results. You can see the page rank in Google yahoo or in many others browser and many other statistics of the website that is displayed in the Google search results. An awesome tool for web developers.

Get this from here: http://tools.seobook.com/firefox/seo-for-firefox.html

 

clip_image013[4]

This is useful when you want to know that on which type of web server the website you’re visiting is hosted. This will automatically displays the web server type of the website in the status bar.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/2036

 

clip_image014[4]

This add-on show the IP address of the website in the status bar of the firefox browser. Sometimes this is useful when you want to know the IP address of a particular website. It’s better than searching or pinging the website using the “who is” websites or using cmd prompt.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/590

 

clip_image015[4]

This add-on is used to open the tab in new window. It is useful sometimes, you should have this add-on. You can find it when you right click on a tab.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/2062

 

clip_image016[4]

Time Tracker tracks the time you spent in your web browser. it displays this tracking I the status bar.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/1887

 

clip_image017[4]

Web developer toolbar, a very useful and good tool for web developers, you must have this tool of you’re using firefox. This tool adds a toolbar in your firefox browser, There are many functionalities provided by this browser, you just install this tool and have a look of all these, but believe me its AWESOME tool. Which will definitely helps you in web designing.

Get this from here: https://addons.mozilla.org/en-US/firefox/addon/60

List of add-ons installed in my firefox browser

firefox-1

 

These are some add-ons for firefox which I am using and getting benefits from these add-ons and there are hundreds of other tools are present who can help you in many ways.
But I am confused that Microsoft a big name in IT field, not having any kind of add-ons with IE, or may be there are, but they are not popular, but I think they are not having anything, and also in comparison of everything like Speed, looks, easy to operate firefox is better than IE. But I am a fan of Microsoft Company, so I request them to develop a good and fast browser. And I appreciate firefox team for making such a cool and awesome browser keep the spirit up and hope that Firefox3 will add many other feature which helps user and web developer.
And if you know any other cool add-on which can help people to improve surfing experience, so please share the same with us.

Give your valuable comments.
Thanks

Reference : Prashant Pandey (TechAhead)

*******

kick it on DotNetKicks.com
Introduction
Hi, in this article I am going to explain you about the use of “radio button” control inside an “ASP.NET Grid View” control. This sounds that it’s easy to put the radio button inside a grid view control, but you are wrong it’s not easy as it sounds. There are many factors which makes this problem complex to solve. But as you know the things looks “impossible”, who ultimately says “I am possible”.  So let’s take a look of this problem and solution for the same.

What is the problem?
The problem is, sometimes we (web developers) needs to display a data to the user which requires a radio button control, means for selection purpose or something. Let’s say you have a list of products out of which you want user can select only one product, so radio button help us that user can select only one product. List something like below:

geid-radio1


Description of the problem and its solution :)
So in the above displayed case we need to put radio button control inside a column in the grid view. Now as you know in asp.net we use the grid view control to display the data in the tabular format, grid view is an element in which you just need to specify the field name (fields that are present in your dataset) which you want to display. And then it will automatically bind those fields and displays all the data to the user in a tabular format.
But according to our problem we need to have a radio button control inside a column in the grid view.
In the grid view there are 7 predefined column types using those you can bound text data and controls like button, check box etc in the grid view column.
The 7 type of columns are displayed below.
  • Bound Field
  • Checkbox Field
  • Hyperlink Field
  • Image Field
  • Button Field
  • Command Field and
  • Template Field

 

geid-radio2


There are 2-3 fields present which are meant and developed to bind the controls like checkbox, hyperlink, image, and button. But not for radio button, so if you want to display any other control in the grid view columns other than already there then you have to use the Template Field column. In which you can place any control you want.
According to our problem we have to display a radio button inside the grid column then we’ll take the Template field column to get the radio button displayed inside it.

Types of “Radio Button” in ASP.NET
Now the complex things start. I don’t know you people are aware of it or not, but there are two types of radio buttons present in the asp.net
 
  1. HTML radio button control – This is the HTML radio button, this runs on the client side and can’t contact with server directly.
  2. Server radio button control – This is the server side radio button you can access this from the server.
Now the question is which type of radio button to choose to get our problem solved. If we choose the “Server radio button control” then it will create problem because the “groupName” property (which is responsible for single radio button selection among the many radio buttons present in the grid) will work only for the radio button present in the same row, not in the different rows, so this will not work and solve our problem.
Now the other one “HTML radio button control” which solve our problem because it works for the “name” (which is responsible for single selection) different rows, and also for the same row. That means where ever the HTML radio control will find the radio control which is having “name” property as same it will include that radio control in the group also and only single selection is possible.
So the final result of this section is that we’ll go with “HTML Radio Button Control” and we’ll use this in our template field column inside a grid view.
 

Solution code for the problem
I have created an example in Asp.NET (C#) to fill the grid view with a radio button column. Like below:
geid-radio1 
To demonstrate this problem I have created a table in database, an asp.net application, which I am explaining here and later you can download the full source of it.

SQL Table Script:

CREATE TABLE radioproblem
(
    Id INT IDENTITY(1,1),
    Name VARCHAR(50)
)

INSERT INTO radioproblem VALUES(’Prashant’)
INSERT INTO radioproblem VALUES(’Praveen’)
INSERT INTO radioproblem VALUES(’Pratik’)
INSERT INTO radioproblem VALUES(’Aman’)
INSERT INTO radioproblem VALUES(’Shenu’)

SELECT * FROM radioproblem

ASP.NET Application
Asp.net application have a page named “radiosample.aspx”, this page has two Server side buttons (Fill Data and Submit), a label, a grid view and a server side radio button. In the grid view I have a template field (which will contain a HTML radio button control) and two boundfield that are “Id” and “Name”. On the click event of the Fill Data button I am filling the grid with data. When data will be filled in the grid then the Radio button will be automatically rendered in each row, and out of those entire radio buttons you can select only one.
Following I am explaining the markup code of the grid view because we have to change some attributes inside markup code of the grid. The code is:

<asp:TemplateField>
            <ItemTemplate>
                <input
                    type=”radio”
                    name=”gvradio”
                    value=”<%#Eval(”Name”)%>” />
            </ItemTemplate>
            <ItemStyle
HorizontalAlign=”Center”
VerticalAlign=”Middle” />
        </asp:TemplateField>

The markup-code of grid view that you will find inside the example, only the above code deserves an explanation. In the above code we have taken a template field column, in which we have inserted a HTML radio button control,

<input type=”radio” name=”gvradio” value=”<%#Eval(”Name”)%>” />

In the radio button code you have to set the “name” attribute to something which you want and “value” this is basically our database value which you can set using the Eval method and we’ll retrieve when user submit the page. Name property is must because this property insures that only single radio button will be clicked out of all radio buttons having the same name, and also we’ll be able to get the value of this radio button using this name.
So now I think our main problem got solved, we can make use of HTML radio button along with grid view, so that user can select only one record or product from grid view. If you want user can select multiple records then you can make use of ASP.NET or HTML checkbox controls

Hold on guys,
So we have solved the problem of ‘how to put a radio button inside grid view’ and how to restrict the user to select only one entry using radio buttons. But guys this is not the end, there are two more problems for you regarding the grid view and radio button relationship. Let’s discuss both one by one.
 


Getting value of “HTML Radio Button” control present inside grid view
Now our first problem after solving the above problem is “getting the value of selected radio button in asp.net code”. It looks easy but its not, because the radio button is present inside the grid view, so you can’t directly access this control and also it’s a HTML radio button, So according to ASP.NET we can’t access the HTML controls directly in Server side code. So how will we find out that, which product or record user selected?
So there is a way with which we can get the value that which record is selected. Generally you can bind any value with radio button which you ant to access on the post back, but as we know  In every sql database table (mostly) there is a primary key column which identifies each row uniquely; it may be your product id, employee id, recorded etc. So it’s always better to bind that unique field with radio button type of columns so that you can find out each row in grid uniquely, but all depends on your requirement whatever you want bind with radio button control you can bin, like I am binding my table’s “Name” field with radio button in my example so that I can access that which name is selected when user submit the page. Have a look how to do this as I have done below:

<input type=”radio” name=”gvradio” value=”<%#Eval(”Name”)%>” />

value=”<%#Eval(”Name”)%>” you can put your database field name in place of “Name”.
When user will click the submit button then inside the submit button we can access that which value user selected using the following code.

Request.Form["gvradio"];

Using the above code you can get the value selected on click of the submit button. In my example I am do is,on click of submit button I am changing the value of Label1 label present on my web page. Like below:

Label1.Text = Request.Form["gvradio"];

So now you got he value of the radio button in asp.net code also. But there is one more possible problem that can arise problems for you, but d’t worry that also having the solution, lets take a look. 


Selecting the first radio button by default
Another problem is “selecting the first radio button in the grid view by default”, if you’ll not do so then, without selecting any record user will submit the page and hence you have to put a code on server side that user selected any record or not. But for this small thing if we send the user to the server then it will put some amount of load on our server, So to solve this there are two ways out, first is using the checked property (but its not the good way) and second is using JavaScript code.
So the first method is using the checked attribute of the radio button you can set the radio button state as checked. Like below,

<input type=”radio” name=”gvradio” checked=”checked” value=”<%#Eval(”Name”)%>” />

But the above code creates a problem, that is it will select one radio button in the given radio button in grid but it will select the radio button that is present in the last row, not the first one, because as we know grid renders each row one by one, so the row that is rendered in last will be selected. But we have to select the first one, so that user will know that first record selected and if he’ll submit the page then selected row will be submitted. So to select the first radio button of first row we have to make use of JavaScript. As you know that gridview in asp.net I renders itself in HTML Table, Row & Column format when we run this in browser, to solve our problem we’ll use this concept of “HTML Tables”, see the JavaScript code below
o in the above displayed case we need to put radio button control inside a column in the grid view. Now as you know in asp.net we use the grid view control to display the data in the tabular format, grid view is an element in which you just need to specify the field name (fields that are present in your dataset) which you want to display. And then it will automatically bind those fields and displays all the data to the user in a tabular format.
But according to our problem we need to have a radio button control inside a column in the grid view.

<script language=”javascript” type=”text/javascript”>
    function select_first()
    {
        var table=document.getElementById(’<%=gvRadiogrid.ClientID %>’);
        if (table.rows && table.rows.length>0)
        {  
            //Here you need to use 1 for first row. because 0 means its refers the header row in table.   
            var firstrow = table.rows[1];             
            var cell = firstrow.cells[0]; 
            var chkChecked = cell.firstChild;

            while(chkChecked)
            {
                if(chkChecked.tagName==”INPUT” && chkChecked.type==”radio”)
                {
                    chkChecked.checked = ‘checked’;
                    break;
                }
                chkChecked = chkChecked.nextSibling;
            }
        }
    }   
</script>

In above code I am taking the reference of gridview as a table object then after accessing the 1st cell of 1st row and then searching the INPUT tag inside that cell if found then checking that it is a radio button, if yes then selecting the radio button and stooping the loop.
That is fine that we have created a JavaScript which will select the 1st row’s radio button by getting the reference of the grid view in table format. But when we run this function, if we’ll run it on document load then at that time our grid not renders so we’ll get the nullable object error. So to solve this we’ll run this function after our grid renders. That means by pasting the following code in our markup file after the markup of gridview.

<script type=”text/javascript” language=”javascript”>select_first();</script>

put the above code after the grid tag (</asp:GridView&gt ;) close. So that it will run after the grid completely rendered and hence it will select the radio button.

Download the example code
Download the zip file and change the  SQL database name, SQL Server username and password, and also make a table using the script given in the example, because that table is used to demonstrate the application.

download

TI have tried my best to explain all possible problem of gridview with radio button, else you can download and run the sample application. To run the code you have to create the table in SQL and have to give the SQL username and password in the code file.

If feel any problem in understanding the code then please comment here.


Give your comments.
Thanks

Reference : Prashant Pandey (TechAhead)

*******

kick it on DotNetKicks.com
Introduction
Hi, this article will give you how to add a script which will add the site to your browser’s favorite’s (IE) or to bookmark’s (Firefox) on click on any element in HTML like hyperlink, button etc. So let’s take a look.

What is bookmark in browsers?
Bookmark, is a feature provided by all the latest browsers. Using this feature you can add any site to the bookmark list, so that later if you need to visit that site then you can easily retrieve it from your bookmark list and visit the site. This feature is useful because mostly people visits many sites while searching for something and it’s not possible to remember the name of all the sites, at that time this feature works as your “URL remember machine”. You can add all the names in your list and visit them whenever you want.
In Microsoft Internet Explorer we call this feature as Favorites (Add to Favorites) like below,

bookmark3


And except IE in all other browsers like in firefox it is called as Bookmarks (Bookmark this page) like below.
bookmark4 

Shortcut of adding any site which you are visiting to your favorites is Ctrl+D in all browsers.


Code to implement bookmarking in our website
As we know that we can add sites to our bookmark list using Ctrl+D or using the menu’s given in browser itself. But to attract users or just providing a facility we can also implement the same facility in our webpage’s on the click of a link or button using a little code of JavaScript. We’ll provide the link to the user something like below,

bookmark1

When user click on this bookmark link then the same dialog will open which open when we press Ctrl+D keys, like following,

 bookmark2

So, to provide this the code of JavaScript and the HTML code is as follows,


JavaScript Function:

function addbookmark()
{
if ( navigator.appName != ‘Microsoft Internet Explorer’ )
    {
window.sidebar.addPanel(”TechAhead Blog”,”
http://techahead.wordpress.com/”,”");
    }
    else
    {
window.external.AddFavorite(”
http://techahead.wordpress.com/”,” TechAhead Blog “);
    }
}

 

HTML hyperlink code:

<a href=”javascript:void(addbookmark());”>
    Bookmark
</a>

 

If you want to use the button instead of link then you can use that in the same way onclick event of the button.

So the whole code will look something like below:

<html>

<head>

<title>Bookmark Script</title>

<script type=”text/javascript” language=”javascript”>

function addbookmark()

{

if ( navigator.appName != ‘Microsoft Internet Explorer’ )

{

window.sidebar.addPanel(”TechAhead Blog”,” http://techahead.wordpress.com/”,”");

}

else

{

window.external.AddFavorite(”http://techahead.wordpress.com/”,” TechAhead Blog “);

}

}

</script>

</head>

<body>

<a href=”javascript:void(addbookmark());”>
    Bookmark
</a>

</body>

</html>

I have this script but I am also facing a problem with this script, actually on net if you’ll search for the scripts then they are very large and complex to use and understand, the above script is easy, simple and short, but the problem is its not working in Safari browser, its working fine in IE and Firefox but not in Safari, So guys please let me know if anyone can give me simple easy script which work in all browsers.
Hope this will help you guys,

Give your comments.
Thanks

Reference : Prashant Pandey (TechAhead)

*******

kick it on DotNetKicks.com
Introduction
Hi guys, here I am with a new and interesting article. This article related to web development, I have used the XHTML and CSS languages to demonstrate example in this article. In this article you’ll find a great and simple technique of CSS and XHTML to make icons in web page. Most of the sites using this trick to create the icons in their site. May be you people already know this but I found this interesting and I think this will help a beginner level web developer a lot, so I am including this in my blog (techAhead).

Concept and implementation of “CSS ICONS”
I think I can explain this more clearly to you by giving you some visual examples. Basically we use this trick to create icons in the website to create the look and feel of the web page more users friendly and attractive. The best example I can give you is Orkut.com a social community site, they are using the icons in their menus like as below:

orkut-menu


Imagine orkut without these cool and cute icons, if someone asked me to “remove these icons or not?” Then my personally thought would be NO. They gives a cool look to orkut, these icons are like make up of web page.
Now after this entire explanation lets move on to real question, is it difficult to do create these icons??, few weeks ago someone asked me that can you create some thing like below,
orkut-simple-menu

I said yes why not, take and image tag and then your text, just and it’s completed. Like below:

<img src=”myicon.png” /> profile

But this is not so easy, yeah what I said in previous line (with using image and text) its is possible but alignment will be a major issue in that case, your text and image will not be aligned properly and hence it will not achieve the perfection.
So to solve this problem you can make use of CSS with XHTML. Like below I have done:
Here I am making a html page with using CSS. The code is below:


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”
http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>CSS icon demo</title>

<style media=”screen” type=”text/css”>
/*CSS Class */
.icon_demo{
padding:3px 0px 3px 20px;
background:url(images/info.png) no-repeat left;
}
</style>
</head>

<body>

<!—HTML Code.– >
<span class=”icon_demo”>Information</span>

</body>
</html>


The above code will produce the following output.

css-demo

In the above code, icon_demo is the CSS icon class which is responsible for setting the icon image in the span or in the div properly and padding done to display the text properly. And the span (HTML Code) in which we’ll set the CSS class and hence it will display the icon and text in properly aligned way, you can make use of div tag also instead of span tag. It all depends on your requirements.
You can use these icons in your menus like orkut done, or in links also or anywhere where you think they’ll look cool and perfect.

That’s it. You people try it by yourself and feel free to contact me in case any problem regarding this topic. I know this is a very small problem and solution but I found this interesting one, so I am including it in my blog. Hope it helps someone.
Give your comments.
Thanks

Reference : Prashant Pandey (TechAhead)

*******

kick it on DotNetKicks.com
Introduction
Hi to all, after a long time since my last article, I am back again. Actually I was busy in my MCA (Master of Computer Application) exams. But now the “TechAhead Express” is back again on the track.
So here I am going to give a brief introduction about the new features in VS2005 in brief. Actually these all points are displayed when you installing the VS2005. With setup there is a presentation going on, those are very good points. So I have decided to put those points for all of you. VS2005 released 2 years back, but I think these are some points which everyone wants to read. It’s like a brief introduction of VS2005.
So let’s take a look,

Be More Productive
  • Speed development with enhanced visual designers.
  • Restructure code faster and easier with new refactoring support.
  • Build data-driven solutions faster with built-in designers for tables and queries.

One tool, One framework, Many languages

  • Use the programming languages that best maps to what you know and where you’re headed.
  • Fully employ the .NET Framework from any language – C#, Visual Basic, J#, and C++.
  • Discover a wealth productivity aids for developing with whatever language you choose.

Create Applications for Windows

  • Build professional-looking applications easily with new controls, such as the ToolStrip.
  • Craft data-driven applications faster with enhanced drag-and-drop data binding.
  • Create form layouts quickly with new Smart Tags, Document Outline view, and SnapLines.

Deliver Integrated Solutions

  • Build upon the Windows Server System to create robust, enterprise-grade applications.
  • Use Visual Basic, C# or C++ to author stored procedures for Microsoft SQL Server 2005.
  • Tackle integration challenges with native support for XML Web services.

Discover Innovation in Language Design

  • Discover new language features such as the “My namespace” and anonymous methods.
  • Generics support in the .NET Framework enables developers to write more performant, type-safe code.
  • Gain greater productivity in Visual Basic, C++ or C# with features like Edit and Continue.

Build Better Web Applications with ASP.NET 2.0

  • Write code faster with a powerful new editor which preserves HTML formatting.
  • Discover over 50 new ASP.NET server controls designed to accelerate site development.
  • Use built-in membership and personalization services to enhance your site.

Simplify Deployment and Operations

  • Streamline application deployments and updates with ClickOnce deployment.
  • Detect and install missing prerequisites automatically using the new setup bootstrapper.
  • Incorporate performance counters and event logging mechanisms into applications easily.

Write Less Code

  • Reduce code by up to 70% using new functionality in .NET Framework 2.0.
  • Use Code Snippets to insert and customize large blocks of template code.
  • Use the new Class Designer to author classes and create structured code stubs.
Thanks,

Reference : Visual Studio 2005 Setup, Prashant Pandey (TechAhead)

*******

Introduction
Hi, after a long time I am here with a new article. This article will tell you about the concept of Auto-complete in ASP.NET.

What is Auto-Complete?
Auto-complete is a good and useful feature of popular browsers like Firefox and IE. You’ve seen this many times. You go to an online form and as you start to type in fields you get a drop-down showing values you’ve typed in that field before.
Let’s take the simple and daily use example which I think every programmer will aware of, GOOGLE this is the name every person knows the internet will definitely know. Now here we’ll see the Auto-Complete using the google website. Whenever we type something in the google search box and click search it will display you the results related to that topic, now when again u type the same value it will display that word in the dropdown list below the search textbox automatically. See the following picture which will tell you this more clearly.Here in the below picture I am searching for “techAhead” (my blog), first time there is no dropdown list, when I click the search button it will display you the result related to techAhead. Here is nothing related to Auto-Complete topic but this is the origin of the concept, let’s move to the next picture and see the concept._google1

Now after seeing the results I closed my browser or clicks the back button or by any means I typed the techAhead again in the search box of google see the below picture which will displays a dropdown list this is the actual concept of Auto-Complete.
_google2
As you can see in the above picture that as I typed the “te” then it displays all the keyword or words that I have searched in the google’s search box earlier, So this is the actual Auto-Complete concept, this is not the case with only google’s search box it will be by default in all textboxes displayed on the websites until the Auto-Complete feature is not disabled for that textbox or it will not be enabled if it is a password textbox.

So “The Auto-Complete means a functionality provided by browsers which will automatically fills your textbox fields with the values that you have typed earlier in that same textbox, whenever you start typing with the same values in that textbox that you have entered earlier.”


Is Auto-Complete Useful?
In my point-of view its fifty-fifty (60%(YES) - 40%(NO)). That is 60% out of 100% it’s a useful feature but rest 40% this feature can create problems for you. How?

Advantages
-
Ok let’s take the positive (+ve) part first why it is useful. It is useful feature because it saves your time by filling your earlier values in the textbox automatically as you starts typing, whenever you starts typing the values it will display you the matches according to that values in the dropdown list, if you find that you need to type the value that is displayed in the dropdown then just select that value from either mouse or by arrow keys and click or press enter key, that value will be automatically filled in the textbox.
This feature is especially useful in case of Searching sites like google, at least I think this, because suppose you type something an searched in the google, then you got your result worked according to that finished your work and closed your system, then after sometime you think that you need the same result again but you don’t remember what you searched in the google then no worries because Auto-Complete is there for your help, just double click using mouse or just press the down-arrow keys twice in the textbox it will display you all the words that you searched for in the google. Same as google this feature is useful when you are filling some big and lengthy form again & again on website’s.

Disadvantages
-
Now we have discussed the advantage part of Auto-Complete but lets take a look of disadvantages.
This features help us lot but sometimes, it can harm you if it will not handled properly, Lets suppose someone has developed a site which takes your credit card details for transaction, and also you have no issue in giving the details to that website because it’s a SSL secured website, But In case they forget to disable the auto-complete feature for the credit card number textbox then What, that means if your in the cyber café and you entered you credit card details, you closed the website and gone, after sometime another person sits on that computer and opens the same website then it may the case that he’ll be able to find out your credit card details using this Auto-Complete feature and can misuse your details. OR you typed your email address somewhere in the site and someone if able to know that using this feature can misuse your email address, so this type of risks contains the 40% risk factor about the Auto-complete.

Solution to cure the risk for Auto-Complete
As a programmer if you asked then the simple solution is that where you think that it’s a risk are someone can misuse the user’s information if he find out those using this feature then disable the auto-complete feature for that textbox. I’ll explain it that how to disable this later in this article.
But if you are a normal user then the best and easy way to take prevention from your side is clear the auto-complete data, it can be done by clearing you browsers history, but sometimes the value of auto-complete not gone by clearing the history, so the best and easy way is Double click on the textbox, the dropdown menu containing the values will be displayed if having the values, then move one by one value and delete it by using the Del key in the keyboard. It will permanently clear the values.

How to disable Auto-Complete programmatically
This feature is enabled by default in all browsers, the big deal is to disable this feature properly in all browsers lets look at this, I am a asp.net developer so first i am discussing about the asp.net that how to disable or enable this feature in asp.net, in asp.net textboxes having an attribute (property) that is “AutoCompleteType” when you type this property and the it will display all the types for which you can make enable this feature there are many that’s why I am not discussing all those, Now to disable this you having the values Disabled and None. See the below pictures you’ll understand.
_auto1 _auto2 Now you think that you have disabled this auto-complete and it will not work for that particular textbox now, But this is not true, I don’t know why but these None and Disabled only works with IE in Firefox it will not disable the auto-complete feature and it will display that auto-complete dropdown.
So how to disable this for all browsers, the above property and case will only work for asp.net.
But the below code will work for all the browsers and in all the language like in ASP.NET, PHP, HTML with all browsers IE, Firefox etc. The below code uses a property called “Autocomplete” and value for this is “off”.
_auto3
the above code will disable this feature in all browsers, in asp.net it will display a green line below this property but its not a big deal it will not create any problem for you. It will work. Actually this Autocomplete is the attribute of HTML input field but as you know that asp:textboxes are rendered as HTML input boxes when in the running on the browser so it will work perfectly for asp textboxes.

So here is all about this Auto-Complete concept, may be I left something important related to this concept, if anyone knows such thing then please let me know I’ll include it in my article.
Thanks,

Reference : Prashant Pandey (TechAhead)

*******

kick it on DotNetKicks.com

SQL - Cursors

Introduction
In a relational database, operations are carried out on a complete set of rows in a table. The SELECT statement returns all the rows that satisfy the condition in the WHERE clause of the statement. This complete set of rows that the SELECT statement returns is called a ResultSet.
Some applications cannot work effectively with the entire set as a unit. These applications need a mechanism to work with one row, or a small block of rows at a time. Sometimes multiple processing steps are required on each individual record before moving on to the next record. In these cases, the result set cannot be created by traditional SQL set statements. Now what is the solution in case where we need to access data row-by-row basis?
Microsoft SQL Server answered this question using the concept of Cursors.

Cursors
Cursors are special programming constructs that allow data to be manipulated on a row-by-row basis, similar to other structured programming languages. They are declared like a variable, and then move one record at a time using a loop for control.
Cursors basically works on the concept of LOOPING that is given in almost every programming language.

Before using cursor, you first must declare the cursor. Once a cursor has been declared, you can open it and fetch from it. You can fetch row by row and make multiple operations on the currently active row in the cursor. When you have finished working with a cursor, you should close cursor and deallocate it to release SQL Server resources.

In more simplified way, a cursor normally works in the following manner:

  • Declare a cursor
  • Open a cursor
  • Fetch the data from the cursor
  • You can fetch row by row and make multiple operations on the currently active row in the cursor
  • Close the cursor
  • Deallocate the cursor to release SQL Server resources

You can use the cursors to do the following:

  • Allow positioning at specific rows of the resultset.
  • Retrieve a single row, or set of rows, from the current positions in the resultset.
  • Support data modifications to the rows at the current position in the resultset.
  • Support different levels of visibility to changes that others users make to the database data that is presented in the resultset.
  • Provide T-SQL statements in scripts, stored procedures, and triggers, to access the data in the resultset.

Cursor Syntax – Advanced View
—————————————————————————————————–

Declaring Cursors
Following is the T-SQL Syntax for declaring a cursor:

DECLARE cursor_name CURSOR
[LOCAL | GLOBAL]
[FORWARD_ONLY | SCROLL]
[STATIC | KEYSET | DYNAMIC | FAST_FORWARD]
[READ_ONLY | SCROLL_LOCKS | OPTIMISTIC]
[TYPE_WARNING]
FOR select_statement
[FOR UPDATE [OF column_name [,...n]]]

Explanation:

  • cursor_name – A cursor name can contain maximum of 128 characters.
  • LOCAL - Specifies that cursor can be available only in the batch, stored procedure, or trigger in which the cursor was created. The cursor name is valid only within this scope. The cursor can be referenced by local cursor variables in the batch, stored procedure, or trigger, or a stored procedure OUTPUT parameter. “An OUTPUT parameter is used to pass the local cursor back to the calling batch, stored procedure, or trigger, which can assign the parameter to a cursor variable to reference the cursor after the stored procedure terminates”. The LOCAL cursor will be implicitly deallocated when the batch, stored procedure, or trigger terminates, unless the cursor was passed back in an OUTPUT parameter. If it is passed back in an OUTPUT parameter, the cursor is deallocated when the last variable referencing it is deallocated or goes out of scope.
  • GLOBAL - Specifies that cursor is global to the connection. The cursor name can be referenced in any stored procedure or batch executed by the connection. The GLOBAL cursor will be implicitly deallocated at disconnect.
  • FORWARD_ONLY - Specifies that cursor can only fetch data sequentially from the first to the last row. FETCH NEXT is the only fetch option supported. “That means with this type of cursors you can’t fetch the first, previous or last record in the cursor result set, you can only fetch the next record in the resultset available.” If FORWARD_ONLY is specified without the STATIC, KEYSET, or DYNAMIC keywords, the cursor operates as a DYNAMIC cursor. When neither FORWARD_ONLY nor SCROLL is specified, FORWARD_ONLY is the default, unless the keywords STATIC, KEYSET, or DYNAMIC are specified. STATIC, KEYSET, and DYNAMIC cursors default to SCROLL. FAST_FORWARD and FORWARD_ONLY are mutually exclusive; if one is specified, the other cannot be specified.
  • STATIC - Specifies that cursor will use a temporary copy of the data instead of base tables. This cursor does not allow modifications and the modifications made to base tables are not reflected in the data returned by fetches made to this cursor. “That means when cursor is running, if at that time you’ll made any modification in the data of the table that you are using currently in the cursor then the changes made to the data will not reflect in the cursor resultset”.
  • KEYSET - Specifies that the membership and order of rows in the cursor are fixed when the cursor is opened. The set of keys that uniquely identify the rows is built into a table in tempdb known as the keyset. Changes to nonkey values in the base tables, either made by the cursor owner or committed by other users, is visible as the owner scrolls around the cursor. Inserts made by other users are not visible (inserts cannot be made through a Transact-SQL server cursor). If a row is deleted, an attempt to fetch the row returns an @@FETCH_STATUS of -2. Updates of key values from outside the cursor resemble a delete of the old row followed by an insert of the new row. The row with the new values is not visible, and attempts to fetch the row with the old values return an @@FETCH_STATUS of -2. The new values are visible if the update is done through the cursor by specifying the WHERE CURRENT OF clause.
  • DYNAMIC - Specifies that cursor reflects all data changes made to the base tables as you scroll around the cursor. FETCH ABSOLUTE option is not supported with DYNAMIC cursor.
  • FAST_FORWARD - Specifies that cursor will be FORWARD_ONLY and READ_ONLY cursor. The FAST_FORWARD cursors produce the least amount of overhead on SQL Server.
  • READ ONLY - Prevents updates from being made through this cursor. The cursor cannot be referenced in a WHERE CURRENT OF clause in an UPDATE or DELETE statement. This option overrides the default capability of a cursor to be updated.
  • SCROLL_LOCKS - Specifies that positioned updates or deletes made through the cursor are guaranteed to succeed. Microsoft SQL Server locks the rows as they are read into the cursor to ensure their availability for later modifications. SCROLL_LOCKS cannot be specified if FAST_FORWARD is also specified.
  • OPTIMISTIC - Specifies that positioned updates or deletes made through the cursor do not succeed if the row has been updated since it was read into the cursor. SQL Server does not lock rows as they are read into the cursor. It instead uses comparisons of timestamp column values, or a checksum value if the table has no timestamp column, to determine whether the row was modified after it was read into the cursor. If the row was modified, the attempted positioned update or delete fails. OPTIMISTIC cannot be specified if FAST_FORWARD is also specified.
  • TYPE_WARNING - Specifies that if the cursor will be implicitly converted from the requested type to another, a warning message will be sent to the client.
  • select_statement - select_statement is a standard SELECT statement that defines the result set of the cursor. The keywords COMPUTE, COMPUTE BY, FOR BROWSE, and INTO are not allowed within a select_statement of a cursor declaration.
  • UPDATE [OF column_name [,...n]] - Specifies that all cursor’s columns can be updated (if OF column_name [,...n] is not specified), or only the columns listed in the OF column_name [,...n] list allow modifications.

Opening a Cursor
Once a cursor has been declared, you must open it to fetch data from it. To open a cursor, you can use the following syntax:

OPEN { { [GLOBAL] cursor_name } | cursor_variable_name}

Explanation:
  • GLOBAL - If this argument was not specified and both a global and a local cursor exist with the same name, the local cursor will be opened; otherwise, the global cursor will be opened.
  • cursor_variable_name - The name of a cursor variable that references a cursor.

After a cursor is open, you can determine the number of rows that were found by the cursor, In other words you can say that how many number of rows your query will return on which you are running the cursor. To get this number, you can use @@CURSOR_ROWS scalar function.


Fetching data from Cursor
Now your cursor is declared for a particular result set and you have opened your cursor using OPEN command, now you can fetch data from it row by row and make multiple operations on the currently active row in the cursor. To fetch data from a cursor, you can use the following syntax:

FETCH
[ [ NEXT | PRIOR | FIRST | LAST
| ABSOLUTE {n | @nvar}
| RELATIVE {n | @nvar}
]
FROM
]
{ { [GLOBAL] cursor_name } | @cursor_variable_name}
[INTO @variable_name[,...n] ]

Explanation:

  • NEXT - The default cursor fetch option. FETCH NEXT returns the next row after the current row.
  • PRIOR - Returns the prior row before the current row.
  • FIRST - Returns the first row in the cursor.
  • LAST - Returns the last row in the cursor.
  • ABSOLUTE {n \| @nvar} - If n is a positive integer, it fetches the nth row in a cursor. If n is a negative integer, it fetches the nth row before the last row. If n is 0, no row is fetched.
  • RELATIVE {n \| @nvar} - If n is positive, it fetches the nth row from the previously fetched row. If n is negative, it fetches the nth row before the previously fetched row.If n is 0, the same row is fetched again.
  • GLOBAL - If this argument was not specified and both a global and a local cursor exist with the same name, the local cursor will be fetched; otherwise, the global cursor will be fetched.
  • cursor_variable_name - The name of a cursor variable that references a cursor.
  • INTO @variable_name[,...n] - Allows data returned from the cursor to be held in temporary variables. The type of variables must match the type of columns in the cursor select list or support implicit conversion. The number of variables must match the number of columns in the cursor select list.

By default, the FETCH NEXT option works.


Closing a Cursor
Now after declaring and opening the cursor we used the FETCH command to fetch data from the cursor and perform some action on it, now when you have finished working with a cursor, you must close the cursor to release any resources and locks that SQL Server may have used while the cursor was open. To close a cursor, you can use the following syntax:

CLOSE { { [GLOBAL] cursor_name } | cursor_variable_name }

Explanation:
  • GLOBAL - If this argument was not specified and both a global and a local cursor exist with the same name, the local cursor will be closed; otherwise, the global cursor will be closed.
  • cursor_variable_name - The name of a cursor variable that references a cursor.

If you have closed a cursor, but have not deallocated it, you can open it again when needed.


De-allocating a Cursor
When you have finished working with a cursor and want to completely release SQL Server resources that were used by a cursor, you can deallocate a cursor. To deallocate a cursor, you can use the following syntax:

DEALLOCATE { { [GLOBAL] cursor_name } | @cursor_variable_name}

Explanation:
  • GLOBAL - If this argument was not specified and both a global and a local cursor exist with the same name, the local cursor will be deallocated; otherwise, the global cursor will be deallocated.
  • cursor_variable_name - The name of a cursor variable that references a cursor.

Whenever using cursors remember to close and deallocate the cursor. Deallocating a cursor completely removes all cursor references. So, after a cursor is deallocated, it no longer can be opened.


The four API server cursor types supported by SQL Server are:
  • Static cursors - A static cursor always displays the result set as it was when the cursor was opened. Static cursors are always read-only.
  • Dynamic cursors - Dynamic cursors are the opposite of static cursors. Dynamic cursors reflect all changes made to the rows in their result set when scrolling through the cursor.
  • Forward-only cursors - A forward-only cursor does not support scrolling; it supports only fetching the rows serially from the start to the end of the cursor.
  • Keyset-driven cursors - The keyset is the set of the key values from all the rows that qualified for the SELECT statement at the time the cursor was opened.

Why Cursors are Slow
Actually what I observed about cursor is that CURSORS TRAET EVERY ROW AS A SEPRATE RESULT SET. Let’s suppose when we execute two select statements in the Query Analyzer then it will return two result sets in the Result pane. Same in the case of cursors if we are running a cursor to process a result set of 20 rows then it will execute a separate select statement for every row. That’s why if you need to process a resultset of 1000 rows then it will put a huge load on your database server.

Performance Tuning SQL Server Cursors
If possible, avoid using SQL Server cursors. They generally use a lot of SQL Server resources and reduce the performance and scalability of your applications. If you need to perform row-by-row operations, try to find another method to perform the tasks that are as follows.
  • Use WHILE LOOPS
  • Use temp tables
  • Use derived tables
  • Use correlated sub-queries
  • Use the CASE statement
  • Perform multiple queries

More often than not, there are non-cursor techniques that can be used to perform the same tasks as a SQL Server cursor. Some techniques that can work as an alternative of cursors are discussed below,

  • Process less number of records with cursors If you think that you must use a cursor then try to reduce the number of records to process. One way to do this is to move the records that need to be processed into a temp table first, and then create the cursor to use the records in the temp table, not from the original table. This of course assumes that the subsets of records to be inserted into the temp table are substantially less than those in the original table. The lower the number of records to process, the faster the cursor will finish.
  • If the number of rows you need to return from a query is small, and you need to perform row-by-row operations on them, don’t use a server-side cursor. Instead, consider returning the entire rowset to the client and have the client perform the necessary action on each row, and then return any updated rows to the server.
  • If you have no choice but to use a server-side cursor in your application, try to use a FORWARD-ONLY or FAST-FORWARD, READ-ONLY cursor. When working with unidirectional, read-only data, use the FAST_FORWARD option instead of the FORWARD_ONLY option, as it has some internal performance optimizations to speed performance. This type of cursor produces the least amount of overhead on SQL Server. If you are unable to use a fast-forward cursor, then try the following cursors in this order, until you find one that meets your needs. They are listed in the order of their performance characteristics, from fastest to slowest: dynamic, static, and keyset.
  • Avoid using static/insensitive and keyset cursors, unless you have no other choice. This is because they cause a temporary table to be created in tempdb database, which increases overhead and can cause resource contention issues.
  • If you have no choice but to use cursors in your application, try to locate the SQL Server tempdb database on its own physical device for best performance. This is because cursors use the tempdb for temporary storage of cursor data. The faster your disk array running tempdb, the faster your cursor will be.
  • Using cursors can reduce concurrency and lead to unnecessary locking and blocking. To help avoid this, use the READ_ONLY cursor option if applicable, or if you need to perform updates, try to use the OPTIMISTIC cursor option to reduce locking. Try to avoid the SCROLL_LOCKS cursor option, which reduces concurrency.
  • When you are done using a cursor, don’t just CLOSE it, you must also DEALLOCATE it. Deallocation is required to free up the SQL Server resources used by the cursor. If you only CLOSE the cursor, locks are freed, but SQL Server resources are not. If you don’t DEALLOCATE your cursors, the resources used by the cursor will stay allocated, degrading the performance of your server until they are released.
  • If it is appropriate for your application, try to load the cursor as soon as possible by moving to the last row of the result set. This releases the share locks created when the cursor was built, freeing up SQL Server resources.
  • If you have to use a cursor because your application needs to manually scroll through records and update them, try to avoid client-side cursors, unless the number of rows is small or the data is static. If the number of rows is large, or the data is not static, consider using a server-side keyset cursor instead of a client-side cursor. Performance is usually boosted because of a reduction in network traffic between the client and the server. For optimum performance, you may have to try both types of cursors under realistic loads to determine which is best for your particular environment.
  • When using a server-side cursor, always try to fetch as small a result set as possible. This includes fetching only those rows and columns the client needs immediately. The smaller the cursor, no matter what type of server-side cursor it is, the fewer resources it will use, and performance will benefit.
  • If you need to perform a JOIN as part of your cursor, keyset and static cursors are generally faster than dynamic cursors, and should be used when possible.
  • If a transaction you have created contains a cursor (try to avoid this if at all possible), ensure that the number of rows being modified by the cursor is small. This is because the modified rows may be locked until the transaction completes or aborts. The greater the number of rows being modified, the greater the locks, and the higher the likelihood of lock contention on the server, hurting performance.
  • In SQL Server, there are two options to define the scope of a cursor. LOCAL and GLOBAL keywords in the DECLARE CURSOR statement are used to specify the scope of a cursor. A GLOBAL cursor can be referenced in any stored procedure or batch executed by a connection. LOCAL cursors are more secure as they cannot be referenced outside the procedure or trigger unless they are passed back to the calling procedure or trigger, or by using an output parameter. GLOBAL cursors must be explicitly deallocated or they will be available until the connection is closed. For optimum performance, you should always explicitly deallocate a cursor when you are done using it. LOCAL cursors are implicitly deallocated when the stored procedure, the trigger, or the batch in which they were created terminates. We can use LOCAL cursors for more security and better scope of the cursor in our application, which also helps to reduce resources on the server, boosting performance.
  • Consider using asynchronous cursors if you expect your result set to be very large. This allows you to continue processing while the cursor is still being populated. While it may not actually speed up your application, it should give the appearance to your end users that something is happening sooner that if they have to wait until the entire cursor is populated.
  • If you have to use a cursor, break out of the cursor loop as soon as you can. If you find that a problem has occurred, or processing has ended before the full cursor has been processed, then exit immediately.
  • If you are using the same cursor more than once in a batch of work, (or within more than one stored procedure), then define the cursor as a global cursor by using the GLOBAL keyword. By not closing or deallocating the cursor until the whole process is finished, a fair amount of time will be saved, as the cursor and the data contained will already be defined, ready for you to use.

Eliminating Cursors
Now as you can see that there are many server performance related problems with SQL cursors, so we must have to find out any alternative of cursors and there are some possible alternatives are listed above in this article. But if you take my opinion I think WHILE LOOPS are the best way to replace cursors. But in performance point of view it’s obvious that while loops increases the performance in comparison of cursors but it all depends on the requirement of the application and the type and amount of data you need to process. So take a look of WHILE LOOP using the following example.
The following code is done with SQL cursors.

DECLARE @item_category_id INT
DECLARE @order_id INT
DECLARE @purchase_order_id INT
DECLARE item_cursor CURSOR FAST_FORWARD FOR
SELECT it.item_category_id, ord.order_id FROM dbo.item_categories it
INNER JOIN dbo.orders ord ON ord.item_category_id = it.item_category_id
WHERE ord.order_date >= ‘1-sep-05′ AND it.isSuspended != 1
OPEN item_cursor
FETCH NEXT FROM item_cursor INTO @item_category_id, @order_id
WHILE @@FETCH_STATUS = 0
BEGIN

EXEC dbo.usp_generate_purchase_order @item_category_id, @order_id, @purchase_order_id OUTPUT

/*Call other code here to process your purchase order for this item*/
FETCH NEXT FROM item_cursor INTO @item-category_id, @order_id
END

Now take a look of alternative view of performing the cursor type of functionality using WHILE LOOPS.

–Declare variables
DECLARE @item_category_id INT
DECLARE @order_id INT
DECLARE @purchase_order_id INT
–Declare a memory table
DECLARE @item_table TABLE (primary_key INT IDENTITY(1,1) NOT NULL,
–THE IDENTITY STATEMENT IS IMPORTANT!
item_category_id INT,
order_id INT)
–now populate this table with the required item category values
INSERT INTO @item_table
SELECT — Same SELECT statement as that for the CURSOR
it.item_category_id, ord.order_id FROM dbo.item_categories it
INNER JOIN dbo.orders ord ON ord.item_category_id = it.item_category_id
WHERE ord.order_date >= ‘1-sep-05′ and it.isSuspended != 1
DECLARE @item_category_counter INT
DECLARE @loop_counter INT
SET @loop_counter = ISNULL(SELECT COUNT(*) FROM @item_table),0)
– Set the @loop_counter to the total number of rows in the
– memory table
SET @item_category_counter = 1
WHILE @loop_counter > 0 AND @item_category_counter <= @loop_counter
BEGIN
SELECT @item_category_id = item_category_id ,@order_id = order_id
FROM @item_table WHERE primary_key = @item_category_counter
–Now pass the item-category_id and order_id to the OUTPUT stored procedure
EXEC dbo.usp_generate_purchase_order @item_category_id, @order_id, @purchase_order_id OUTPUT
/*Call other code here to process your pruchase order for this item*/
SET @item_category_counter = @item_category_counter + 1
END

That’s it! You have just converted your CURSOR statement to a typical SQL WHILE loop. In the above query it is noticed that this approach gave a 75% increase in performance over the statement using the CURSOR keyword. But again all depends on you query criteria, but yes it is sure that it will increase your query performance.

In this article I tried my best to put all things related to cursors, but no one is perfect, so if anyone having any interesting or special concepts about Cursors then do comment on this article I’ll include those concepts also in my article.

Thank you,

*******

kick it on DotNetKicks.com
Reference from and many thanks to following websites and articles:
Microsoft’s Book Online For SQL Server 2000
Sql-Server-Performance
Sql Server Central
Introduction
Difference between Server.Transfer and Server.Execute.

Server.Transfer v/s Server.Execute
  • Both Server.Transfer and Server.Execute were introduced in Classic ASP 3.0 (and still work in ASP.NET).
  • When Server.Execute is used, a URL is passed to it as a parameter, and the control moves to this new page. Execution of code happens on the new page. Once code execution gets over, the control returns to the initial page, just after where it was called. However, in the case of Server.Transfer, it works very much the same, the difference being the execution stops at the new page itself (means the control isn’t returned to the calling page).
  • In both the cases, the URL in the browser remains the first page URL (doesn’t refresh to the new page URL) as the browser isn’t requested to do so.

These are common differences, if anyone knows any other difference other than these then please give your comments.

Thank you,

Reference : Prashant Pandey (TechAhead)

*******

kick it on DotNetKicks.com
Reference from and many thanks to following websites and articles:
DotNEtUncle
Introduction
This article tell you the difference between Server.Transfer and Response.Redirect.

Server.Transfer v/s Response.Redirect
Both “Server” and “Response” are objects of ASP.NET. Server.Transfer and Response.Redirect both are used to transfer a user from one page to another page. Both are used for the same purpose but still there are some differences are there between both that are as follows:
  • Syntactically both are different, if you want to transfer the user to a page named newpage.aspx then syntax for both methods will be,

Response.Redirect(“newpage.aspx”) and Server.Transfer(“newpage.aspx”)

  • 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.

Roundtrip means in case of Response.Redirect it first sends the request for the new page to the browser then browser sends the request for the new page to the webserver then after your page changes But in case of Server.Transfer it directly communicate with the server to change the page hence it saves a roundtrip in the whole process.

  • If you are using Server.Transfer then you can directly access the values, controls and properties of the previous page which you can’t do with Response.Redirect.

Suppose you are currently on the Page1.aspx and now you are transferring the user to the Page2.aspx using Response.Redirect then When the Page2 page is requested, Page1 has been flushed from the server’s memory and no information can be retrieved about it unless the developer explicitly saved the information using some technique like session, cookie, application, cache etc. But in case of Server.Transfer variables can stay in scope and Page2 can read properties directly from Page1 because it’s still in memory, as you know the Server.Transfer just changes the focus from page1 to page2 So in this case browser doesn’t know that any change is happen there that’s why with this method you can access the information about the previous page.

  • Response.Redirect changes the URL in the browser’s address bar. So they can be bookmarked. Whereas Server.Transfer retains the original URL in the browser’s address bar. It just replaces the contents of the previous page with the new one.

Actually in case of Server.Transfer it directly contact with the webserver for the new page request, it doesn’t involve the browser, so that browser doesn’t know that there is any change happen. But in case of Response.Redirect as you know it first send the request (for new page) to the browser then further processing will be performed, so here browser knows that yes there is some change in the browser window that’s why it changes the URL in the address bar.
So, the matter “No change of address in the browser address bar” This is a good thing if you see it from security point of view but it creates problem in case if you refresh your page or in case you want to add bookmark of that page. In case of refresh and bookmark it will add perform both the action with the URL currently present in the address bar, but as you know Server.Transfer doesn’t changes the URL, so sometimes it creates problem.

  • Response.Redirect can be used for both .aspx and html pages whereas Server.Transfer can be used only for .aspx pages and is specific to ASP and ASP.NET.

With Response.Redirect you can redirect the user to the both type of pages .html or .aspx like below,
Response.Redirect(“mypage.html”) OR Response.Redirect(“OtherPage.aspx”)
But in case of Server.Transfer you can only work with .asp or .aspx page like below
Server.Transfer(“mypage.asp”) OR Server.Transfer(“OtherPage.aspx”)

  • 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.

Suppose on some action on the webpage I want to redirect my user to the http://www.yahoo.com so with Response.Redirect you can redirect your user to the external site, but in case of Server.Transfer you can only work with the .asp or .aspx pages that are present in your site.

Now the question is which to use and when to use? Mostly the Server.Transfer method is preferable to use because Server.Transfer is faster since there is one less roundtrip, but in some people say that Server.Transfer is not recommended since the operations typically flow through several different pages due to which you lose the correct URL of the page, but again all depends on your requirement.
Server.Transfer also allows for more flexibility since you can use HTTPContext.Items to pass variables between pages so, use Server.Transfer when you need to pass context items. Otherwise use Response.Redirect so the user will always see the correct URL in the address bar.

I mentioned the most common differences here if anyone knows any other difference other than these then please give your comments.

Thank you,

Reference : Prashant Pandey (TechAhead)

*******

kick it on DotNetKicks.com
Introduction
Hi, today I am writing a trick which I found while solving my friends problem in SQL. May be you people already aware with this trick but it’s new for me, so I am sharing it with you. Yesterday my friend asked me a problem in SQL, he wants to convert the horizontal data to vertical data, now what is horizontal and vertical data, answer is as follows:
Horizontal Data

_hzdata

AndVertical Data

_vtdata

But my friend not having the data in the table instead he’s having the data in a variable as follows:ABC,ABD,ABE,BAC,BAD,BDE

And then he wants to convert these values like in the following format so that he can store the values in the table as a single column:
ABC
ABD
ABE
BAC
BAD
BDE

For that he’s planning to use a cursor or a while loop, to read the data and get the first three values except the comma and then get the desired result.

So to solve his problem I used the UNION ALL clause and created the following querry.

DECLARE @vSQL AS VARCHAR(1000), @vCode AS VARCHAR(1000)
SELECT @vCode = ‘ABC,ABD,ABE,BAC,BAD,BDE’
SET @vSQL = ‘SELECT ”’ + REPLACE(@vCode, ‘,’, ”’ UNION ALL SELECT ”’) + ””
EXEC (@vSQL)

I think the UNION and UNION ALL operators are the best way to solve this type of problem. His problem is solved but I thought let’s suppose we are having the same situations with tables like the images I displayed above. Then how to do this, to get the solution of the same problem with tables I used the below code.

/*First i created a table HzData which is having 5 columns.*/
CREATE TABLE HzData
(
Code VARCHAR(5),
Code1 VARCHAR(5),
Code2 VARCHAR(5),
Code3 VARCHAR(5),
Code4 VARCHAR(5),
Code5 VARCHAR(5),
)

/*Then i inserted one row in this table.*/
INSERT INTO HzData(Code, Code1, Code2, Code3, Code4, Code5)
VALUES(’ABC’,'ABD’,'ABE’,'BAC’,'BAD’,'BDE’)

SELECT * FROM HzData

/*Now the same problem with tables can be solved in two ways.
you can deside whichever is best sutite