Some day I will know everything. I hope that day never comes.
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 ......
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
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.
Google has taken one step forward to personalize your search engine. Check this out:

Visit
logogle.com for more information.
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 ......
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
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" ......
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 ......
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". ......
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 ......
This weekend is all about GridView control :). I wrote three simple tutorials about GridView. You can read the articles on
www.gridviewguy.com.
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 ......
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.
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. DynamicDrive.com 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. ......
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 ......
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 ......
You can create the SqlDataSource control in Asp.net 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(); ......
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 ......
SqlBulkCopy class in Asp.net 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 ......
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 Asp.net” by Dino and “T-SQL Programming” by Ken Henderson ......
I learned today that page output caching does not cache the images. Output cache only cache the compiled asp.net pages. There is a way to cache the images through your Web Server or IIS.
Check out this post
Caching Images through Web Server
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 ......
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 !
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 ......
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.
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 ......
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 !
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 ......
In Asp.net 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";
Response.Write(myHeader.Title);
OR simply
Page.Header.Title = "This is the page title";
You might face some small problems while migrating Asp.net 1.x application to Asp.net 2.0 Beta 2. This is because the Page model in Asp.net 2.0 has been changed. The codebehind attribute of the Page directive is changed to CodeFile.
If you are migrating from Asp.net 2.0 Beta 1 to Asp.net 2.0 Beta 2 than you need to change the compilewith attribute to Codefile and classname attribute to inherits.
GridViewGuy is deployed, it contains Asp.net articles, free server controls, free .NET development tools as well as list of best GridView articles. Visit the website at www.gridviewguy.com.
I will be updating the website on regular basis soo visit it daily :).
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"
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 ......
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 asp.net 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 ......
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 ......
You can easily extract the file name from the path by using a single method.
System.IO.Path.GetFileName(File1.PostedFile.FileName);