Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes. July 2005 Entries
Connection String Nightmares in Access Database
I never thought using connection string in web.config for Access database could be so frustrating. Whenever I put the connection string and try to feed it to the connection object it always throws the exeption that the path was not found even though I was using Server.MapPath. The problem was that you cannot feed the whole damn connection string to the map path method since it only takes a PATH and no junk. Hence I have to break it down into pieces. Something like this: And then used the following ......

Posted On Saturday, July 30, 2005 9:17 PM

Customizing Visual Studio's Code Generation Templates
I just read this super cool article on codeproject which explains that how you can customize the templates in Visual Studio.NET. Let's say you add a class in your project and you see the commented code which you don't want well, you can easily get rid of it by modifying the templates of Visual Studio. Check it out: Customizing Visual Studio's Code Generation Templates

Posted On Friday, July 29, 2005 1:34 PM

Repeaters gone horizontal
Whenever I use a Repeater control and display data on the screen it always display horizontally. If you want to make it vertical you can simply use the div tags arround the DataBinder method. Although it works as expected but I was wondering if there is a better way to do this.

Posted On Friday, July 29, 2005 1:11 PM
Google has taken one step forward to personalize your search engine. Check this out: Visit for more information.

Posted On Thursday, July 28, 2005 7:26 AM

SQL Server Does not Exist or Access Denied
How many times have you seen this error? SQL SERVER DOES NOT EXIST OR ACCESS DENIED The cause of this error can be different in different cases here are two causes: 1)When specifying connection string please don’t surround server name with curly brackets like this (localhost). 2)Another cause can be Windows firewall which will prevent you from connecting to the database hosted on different server. Here is what you can do. Start menu -> click on run and type -> wscui.cpl -> Select Exceptions -> Add ......

Posted On Wednesday, July 27, 2005 12:11 PM

Exporting GridView to Excel
Exporting Datagrid to excel was pretty straight forward and so does exporting GridView control. The code for both of them is almost identical with one exception that in GridView we need to override the Page.VerifyRenderingInServerForm method. Check out my complete article Exporting GridView to Excel

Posted On Tuesday, July 26, 2005 10:15 PM

Put an end to "Control 'Button2' of type 'Button' must be placed inside a form tag with runat=server"
How many times you have seen this error: Control 'Button2' of type 'Button' must be placed inside a form tag with runat=server. I bet lot of times. This error comes when you place your control outside the form tag. The fix is very easy just go to html view and cut the control code and paste it inside the form tags OR cut the form ending tag and place it after the control tag. A much better way is to actually see where the form tags end. You can easily see this in Visual Studio by selecting "View" ......

Posted On Tuesday, July 26, 2005 12:56 PM

Accessing Invisible Columns of Datagrid ( No big deal !! )
You can always access the Datagrid invisible column through looping. Most of the time when you display data in the Datagrid you hide the first column since its a primary key. Now if you want to access that column you can easily use a DataGridItem to loop through each item of the Datagrid. This is not the only method to access the invisible column. If you have a select column in the Datagrid you can use that also. private void Button1_Click(object sender, System.EventArgs e) { foreach(DataGridItem ......

Posted On Tuesday, July 26, 2005 12:45 PM

GridView Export to Excel Problems
Several days back I wrote an article Exporting Datagrid to Excel, Word and Text Files. I tried the same technique for the GridView control and was smashed with a silly error saying that GridView control must be placed inside the Form tag with runat server = true. I switched to html view and found that GridView is already inside the form tag with runat = server. I googled it and found that many people are facing this problem and no one has found a solution yet. Microsoft has classified it as a "BUG". ......

Posted On Monday, July 25, 2005 2:17 PM

Playing with C# Expressions !
Here are some interesting situations that will raise compile time error: if(1=1) string a = "Hello World"; for(int i=0;i Both the if and the for loop will raise an error. That is because I have declared string 'a' and 'b' on the next line of both the statements without using the parenthesis. You should always include parenthesis even if your conditional statement consist of only one statement. Here is another situation: string a += "Hello World"; The above statement will raise an error because string ......

Posted On Sunday, July 24, 2005 10:58 PM

GridView In-Place editing, populating DropDownList and Selecting Checkboxes.
This weekend is all about GridView control :). I wrote three simple tutorials about GridView. You can read the articles on

Posted On Sunday, July 24, 2005 8:20 AM

Selecting Multiple Checkboxes inside the GridView Control
Selecting values from the checkboxes inside the GridView control is pretty simple. Check out the code below. // StringBuilder object StringBuilder str = new StringBuilder(); // Select the checkboxes from the GridView control for (int i = 0; i Checkout the complete article: Selecting Checkboxes inside the GridView Control ......

Posted On Saturday, July 23, 2005 4:42 PM

Article Categories component has been placed on the main page of
Today I put the categories component on the front page of gridviewguy so users can instantly find out how many articles belong to one category. I am planning to do more updates on the site during the weekened.

Posted On Saturday, July 23, 2005 7:38 AM

Using DHTML tool tips with ASP.NET
DHTML is a great scripting language. Although I have never written any DHTML scripts of my own but I have played around with few of them. is the God of all DHTML websites. I was just browsing the website today and I found a very cool script for making tooltips. I used it in my code and it creates kinda cool effect. Check out the image below: This is loading the data from the Categories table of the Northwind database. I used simple databinding to display the contents on the screen. ......

Posted On Friday, July 22, 2005 12:34 PM

Defining your classes in the code behind
I noted a very interesting thing today. If you are trying to make classes inside your code behind than your class which is at top of the page should always be the one which inherits from the System.Web.UI.Page or else your will not get errors while creating controls on design time. This code will give error message when you drag and drop any server control on the form. public class MyClass { public string name; public void Foo(string cat) { } private void InitializeComponent() { } // public void ......

Posted On Wednesday, July 20, 2005 11:35 AM

Implementing Hit Counters in
Every website needs counter to keep track of visitors. If you are implementing a hit counter always remember to start the count from 10,000 :) just kidding. You can easily make a hit counter by using a Application variable and increase its count in Application_BeginRequest or Session_Start events for every user visit. The problem is that once the server restarts your application level variables will be reinitialized and hence they will loose all count. A good way is to store the visitor count in ......

Posted On Wednesday, July 20, 2005 10:21 AM

Adding SqlDataSource Control programatically in 2.0
You can create the SqlDataSource control in 2.0 dynamically. Always remember to add the control to the Page control using the Controls.Add method. protected void Button1_Click(object sender, EventArgs e) { SqlDataSource s = new SqlDataSource(); s.ID = "mySqlSourceControl"; Page.Controls.Add(s); s.ConnectionString = ConfigurationManager.Connec... s.UpdateCommand = "UPDATE Person SET Name = @Name WHERE PersonID = 6"; ControlParameter param = new ControlParameter(); ......

Posted On Tuesday, July 19, 2005 8:09 PM

You know you are a Geek when..............
You know you are a Geek when you spent 18+ hours in front of the computer screen. You know you are a Geek when you sleep less than 7 hours. You know you are a Geek when you talk about Whidbey with your 4 year old cousin. You know you are a Geek when you send while(0 as a love letter to your fiance. You know you are a Geek when you check your email 100 times a day. You know you are a Geek when your password is in Hexadecimal ......

Posted On Tuesday, July 19, 2005 8:08 AM

Using SqlBulkCopy class to copy data from one table to another
SqlBulkCopy class in 2.0 provides functionality to copy data from one table to another table. This transfer of data is very easy to perform. Check out the following code: string connectionString = ConfigurationManager.Connec... SqlConnection myConnection = new SqlConnection(connectionStr... SqlCommand myCommand = new SqlCommand("SELECT * FROM Person",myConnection); myConnection.Open(); SqlDataReader dr = myCommand.ExecuteReader(); SqlConnection myNewConnection ......

Posted On Monday, July 18, 2005 8:22 PM

Pacing myself for Visual Studio.NET 2005
Visual Studio.NET 2005 might be releasing in couple of months and I am far behind the new technology. I do have Visual Studio.NET 2005 Beta 2 but it has minor bugs that slow me down during my learning process. I have made a habit of waking up early at 5:00 AM to read programming books and articles since after I come home from work at 6:00 PM I am dead tired. Although the fatigue don’t stop me from jogging. Currently I am reading “Introduction to” by Dino and “T-SQL Programming” by Ken Henderson ......

Posted On Monday, July 18, 2005 12:16 PM

Output Cache does not Cache Images
I learned today that page output caching does not cache the images. Output cache only cache the compiled pages. There is a way to cache the images through your Web Server or IIS. Check out this post Caching Images through Web Server

Posted On Friday, July 15, 2005 1:56 PM

Generating Unique Numbers using Random Method
I was trying to find that if the Random Numbers being generated by the Random function are truly Random or not. So I wrote this small piece of code. When I debug the application it never goes into the else of the IsUnique method. But when I run this application "without debugging" it always print "This is not a random Number". Any ideas ! using System; using System.Collections; namespace RandomNumberTest { class Class1 { private static ArrayList randomList = new ArrayList(); private static int notRandom ......

Posted On Friday, July 15, 2005 1:07 PM

Uploading Images to Server Folder and SQL Server 2000 Database
I just wrote an article in which I discussed that how you can upload an image to the server folder as well as the SQL Server 2000 Database. You can view the article at Uploading Images to Server Folder and SQL Server 2000 Database Enjoy !

Posted On Friday, July 15, 2005 5:13 AM

Redirection in the Catch Block
Most of you already know this but those who don't here it is. If you want to redirect to some page in the catch block you will have to supply the second parameter of Response.Redirect method. Something like this: try { // Do some dirty work } catch(Exception ex) { Response.Redirect("Failure.... } Also consider this situation. This will also throw an exception "Thread is being aborted". The reason is the parent try-catch block. You are redirecting in the try block without using the second ......

Posted On Thursday, July 14, 2005 12:03 PM

Large DataSets can cause OutOfMemoryException
Large DataSets can cause OutOfMemoryException. Offcourse this exception is not only confined to DataSets but any container which is heavily populated. Also not surprising that DataSets containing huge amount of data will take longer to load. Hence, always keep the size of the DataSet small and if you want to retreive large data do it in steps rather than in a single shot.

Posted On Thursday, July 14, 2005 7:41 AM

When trying to retrieve the identity of the last row inserted in the table always use SCOPE_IDENTITY instead of @@IDENTITY. If you are simply inserting data into the database table using a simple INSERT query than you won't be able to see the disaster behind using @@IDENTITY. But as soon as you or your fellow developer start using triggers and tries to insert data into another table depending on the insertion in the first table the whole hell will break loose. Here is a small scenario. You write ......

Posted On Wednesday, July 13, 2005 1:03 PM

WinCV is one of the coolest .NET tools. Its a utility that enables you to view all the methods, events, fields, properties associated with a class. You can even view the interfaces as well as the base class. Just search your harddisk for "WinCV.exe". The path in my computer is: "C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\WinCV.exe" Enjoy !

Posted On Wednesday, July 13, 2005 8:34 AM

Microsoft Visual Studio.NET 2005 BETA 2 contains BUGS
I installed Visual Studio.NET 2005 BETA 2 couple of months ago but really give it a shot yesterday. Unfortunatly its filled with bugs. I was not able to perform common and simple tasks. I tried to select a file from the solution explorer and the solution explorer keeps closing on me. I remained calm and patient for a while but what really pissed me when I was not able to write code in the html view. One other guy told me that his windows form screen freezes in the middle. Can you believe that ! I ......

Posted On Tuesday, July 12, 2005 9:57 AM

Changing title of the page at runtime in 2.0
In 2.0 you can change the title of the page at runtime. This is done by using the Header property of the Page class. The best place for this is the PreInit event handler.

IPageHeader myHeader = Page.Header;
myHeader.Title = "Welcome to my Test Page"; 

OR simply
 Page.Header.Title = "This is the page title"; 

Posted On Saturday, July 9, 2005 10:27 PM

Code Behind model of 2.0
You might face some small problems while migrating 1.x application to 2.0 Beta 2. This is because the Page model in 2.0 has been changed. The codebehind attribute of the Page directive is changed to CodeFile. If you are migrating from 2.0 Beta 1 to 2.0 Beta 2 than you need to change the compilewith attribute to Codefile and classname attribute to inherits.

Posted On Saturday, July 9, 2005 8:31 PM

GridViewGuy has been deployed
GridViewGuy is deployed, it contains articles, free server controls, free .NET development tools as well as list of best GridView articles. Visit the website at I will be updating the website on regular basis soo visit it daily :).

Posted On Friday, July 8, 2005 12:56 PM

Sending emails using at scheduled time
I have made a small console application which you can use to add and send emails. You can use the power of Windows Scheduler to schedule an email for a particular time. The complete article can be found at Schedule an email using Windows Scheduler"

Posted On Wednesday, July 6, 2005 9:19 PM

Console.ReadLine() can only takes 256 characters !!
I was making an application couple of days ago in which I had to take input from the Console. The input was string so I thought I can achieve this using string myInput = Console.ReadLine() But unfortunatly Console.ReadLine() only takes 256 characters as input and once 256 characters are typed it will stop taking input from the user. There is a simple way you can increase the input size. In the code below I am setting the OpenStandardInput method of the Console class to the number of characters that ......

Posted On Wednesday, July 6, 2005 2:54 PM

How may I help you !
Ever called a company's technical support and found out that technical help is not so technical at all. I have experienced this alot. I call dell and Webhost4life and ask for technical support. I asked simple question like what files do I need to upload for my application and they answer "Whatever files you need to run". Dell technical support is even worse. I had to wait on the phone for 1 hour and they keep transfering me from one representative to other and than I had to explain the whole ......

Posted On Wednesday, July 6, 2005 12:57 PM

A very good book on design patterns
Books on design patterns are usually very hard to read and boring to follow. I recently read few chapters of a design pattern book named "Head First design patterns" by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra Head first design patterns The book is written in java language but you can easily use it for C# due to the similarity of the languages. The good thing about this book is that its not boring and keep you engage in reading by supplying small jokes and cute cartoons ......

Posted On Tuesday, July 5, 2005 2:52 PM

Extracting File name from the path
You can easily extract the file name from the path by using a single method. System.IO.Path.GetFileName(File1.PostedFile.FileName);

Posted On Monday, July 4, 2005 11:30 AM

Copyright © Mohammad Azam | Powered by: