ASP.NET 2.0

Import Data From Excel to Access with ASP.NET

calendar_today 09 July 2008 09:19

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

Building on my previous article on importing text files of various formats to an Access database, here's how to do the same thing simply and efficiently with Excel files.

AccessDataSource, SqlDataSource and connecting to Access databases in ASP.NET

calendar_today 17 May 2008 09:48

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

There are a variety of options for connecting to Access databases within ASP.NET pages. This article attempts to cover the choices and offer recommendations for getting the best out of Access.

80040E14 - MS Access Syntax Error messages

calendar_today 01 May 2008 11:06

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

This short article deals with the following common MS Access-related error messages:

Simple Login and Redirect for ASP.NET and Access

calendar_today 01 May 2008 10:02

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

Quite often, I see questions asked about creating a simple login page for use with Access from people who don't want to take advantage of the built-in Forms Authentication framework within ASP.NET. The following samples show how relatively easy this is to accomplish.

Solving the Operation Must Use An Updateable Query error

calendar_today 30 April 2008 22:48

ASP.NET 2.0 MS Access ADO.NET ASP.NET 3.5

The unbelievably cryptic Operation Must Use An Updateable Query error is the bane of developers who are just starting out with Access and ASP.NET. You've done your code, plopped your database file in the App_Data folder (or at least, you should have done), and try to run a page that INSERTs or UPDATEs records, and it all stops dead. This brief article explains the cause of the error, and the steps required to stop it recurring.

How to get your forum question answered - avoid thread-jacking

calendar_today 13 November 2007 12:33

ASP.NET 2.0

If you have just been directed to this page, it may be because you have just thread-jacked. If you are not sure what that means, read on for an explanation, and some guidance.

An ASP.NET Search Engine with MS Access for optional search criteria

calendar_today 12 November 2007 15:15

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

Creating a search interface for one user-supplied value is pretty straightforward: a TextBox for input, a Button and some SQL that searches one or more fields where the values are LIKE '%' + @searchterm + '%' is all that is needed. While it works, this approach is not very flexible. For example, what if you wanted to search for an Employee whose last name contains "a", and don't want those where the first name or city contains "a"? The traditional solution to this is to dynamically construct the SQL statement based on what values were passed by the user. However, building the SQL string can get repetitive, boring and messy. Here is a cleaner way to allow the user to narrow down searches across multiple criteria with the use of optional parameters, and just 3 lines of programming code.

Referencing CheckBoxes in GridView, Repeater and DataList controls

calendar_today 30 August 2007 10:29

ASP.NET 2.0 ASP.NET Web Forms

If you want to find which CheckBoxes were selected in a multiple record DataBound control, the way that you you do it depends on the type of control you use. These examples demonstrate a CheckBox control being added to a GridView, Repeater and a DataList. For simplicity, I have placed all three controls on the same page, and used the Access version of theNorthwind database. One AccessDataSource control is used to bind the results of "SELECT [CategoryID], [Description], [CategoryName] FROM [Categories]" to all three controls.

ViewState, form fields, labels and Javascript

calendar_today 25 August 2007 12:34

ASP.NET 2.0 Javascript ASP.NET Web Forms

An interesting question came up on the ASP.NET forums asking why a TextBox which has its value changed by client-side Javascript persists those changes across postbacks, while a Label does not. And in a nut shell, this question covered two of the biggest causes of confusion among newcomers to ASP.NET: the difference between ViewState and IPostBackDataHandler; and the difference between client-side operations and server-side operations.

Bind Data From a SqlDataSource to a Label

calendar_today 25 August 2007 10:32

ASP.NET 2.0 ADO.NET ASP.NET Web Forms

Label controls in ASP.NET don't have a smart tag that allows you to select a data source, so at first glance, it is not easy to see how to bind a value returned from a SqlDataSource or AccessDataSource control to the label. Here's how to programmatically access the data returned by such a DataSource and apply it to a non-databound control.

Object reference not set to an instance of an object and INamingContainer

calendar_today 21 August 2007 11:36

ASP.NET 2.0 ASP.NET Web Forms

A list of standard ASP.NET web controls that implement INamingContainer

Consuming RSS feeds in an ASP.NET page

calendar_today 18 August 2007 23:12

ASP.NET 2.0 ASP.NET Web Forms

I like reading Scott Guthrie's blog. Trouble is, I get so busy, I forget to go over there and have a look to see what's new. I was searching for something the other day, and stumbled across someone else's blog (I forget whose), but I noticed that they had the 5 most recent items in Scott's blog embedded in their home page. It was only then that I discovered that Scott Mitchell has written a whole load more tutorials on Data Access, and that these have been available for a while. So I got to thinking that I should add a feed from Scott G's site onto the home page here, so I can be updated more quickly. Here's the bare bones of how I did it.

List the contents of a folder and link to each file

calendar_today 10 August 2007 21:33

ASP.NET 2.0

Iterating the contents of a folder is straightforward using classes from System.IO, and listing them as links to the actual file just requires a bit of html added to each file name.

Exporting data to a CSV, tab delimited or other text format

calendar_today 02 August 2007 23:41

ASP.NET 2.0 ADO.NET

A question that often comes up in forums is how to export data to a CSV file, or other text format. Here's a method that takes data from a DataReader and writes it to a file.

Displaying One-To-Many Relationships with Nested Repeaters

calendar_today 27 July 2007 14:24

ASP.NET 2.0 ADO.NET ASP.NET Web Forms

This item could also have been entitled "Displaying Master-Detail Data" or "Displaying Categorised Data", but the principal is the same: you have what are essentially headings or categories, and a group of entries that belong to each heading that you want to display. Typical examples would include the Models of cars by Manufacturer, or Employees by Department. Here's how to do it quite simply using nested Repeaters.

Customising a ListControl's DataTextField value

calendar_today 06 July 2007 12:19

ASP.NET 2.0 ASP.NET Web Forms

The DataTextField property is used with ListControls - RadioButtonList, CheckBoxList etc to specify a field in the DataSource property to display as the items of the list in the list control. Sometimes, however, you don't want just the value from one database field to appear in the list, and there are a couple of ways to achieve this, depending on what you want to do.

A more efficient RSS feed with C#

calendar_today 06 June 2007 23:15

C# ASP.NET 2.0

The contents of an RSS feed only change when items that appear in it are added or amended, so the feed created in the previous article (Create an RSS Feed In ASP.NET 2.0 C#) is rather inefficient, in that the output is generated everytime the feed is requested. Here's an improvement.

Saving a user's CheckBoxList selection and re-populating the CheckBoxList from saved data

calendar_today 03 June 2007 22:56

ASP.NET 2.0

The user has gone to the trouble of selecting a list of checkboxes to indicate their choices. Now you need to re-present their selections so that they can edit them. How do you make sure the correct checkboxes are ticked?

Basic file management with System.IO in ASP.NET

calendar_today 29 May 2007 12:37

C# ASP.NET 2.0

Some basic file and folder management tasks that require the use of classes inside System.IO

How to read a remote web page with ASP.NET 2.0

calendar_today 21 May 2007 21:38

C# ASP.NET 2.0

Two classes in the System.Net namespace make it very easy to obtain the html of a remote web page. These are the HttpWebRequest and HttpWebResponse. Here's a quick demo.

Programmatically accessing data from DataSource controls

calendar_today 16 May 2007 10:06

C# ASP.NET 2.0 ADO.NET

For the main part, the DataSource controls are incredibly easy to work with. You just drag them onto your page in Design View, wire them up to a connection and provide some kind of command (ad hoc sql query or the name of a stored procedure - saved query in Access), then link them to a databound control on the page using its DataSource property. Then you run the page and all your data appears. But what if you want to get at one or more values from the returned data to do something else with it, like display it in a control that doesn't expose a DataSource property?

Binding data to a DropDownList with ADO.NET

calendar_today 11 May 2007 22:35

ASP.NET 2.0 MS Access ADO.NET

Using ADO.NET to pull data from the Northwind database (Access version), using the saved query Current Product List.

Send form content by email in ASP.NET

calendar_today 10 May 2007 22:53

C# ASP.NET 2.0 VB.Net

Using ASP.NET to send the contents of a form by email is a common requirement. This sample looks at generating an email using System.Net.Mail in both plain text and html format from a very basic Contact Us form.

ASP.NET and Ajax - using XmlHttpRequest

calendar_today 08 May 2007 17:32

ASP.NET 2.0 AJAX Javascript

If you are not interested in using the ASP.NET AJAX library offered for ASP.NET, but would like to feature small amounts of AJAX functionality on your pages, you can do this easily with some javascript and a receptive page.

How to highlight a GridView's row on hover

calendar_today 06 May 2007 20:50

C# ASP.NET 2.0 Javascript

As the user hovers over each row, it becomes highlighted, with the help of a small amount of javascript.

How to make an ASP.NET Table row highlight and become clickable

calendar_today 06 May 2007 20:38

C# ASP.NET 2.0 Javascript HTML

For those people who like to output their data to an asp:Table, highlighting the entire row and making it clickable can make it obvious to the user that some action is expected from them. This emulates the behaviour that can be found in some desktop applications. All that's needed for this is a bit of javascript, and the use of AddAttributes() for the table rows.

Include contents of an html page in an aspx page

calendar_today 05 May 2007 20:44

ASP.NET 2.0 HTML

If you are creating a new ASP.NET application, but have a huge collection of existing content in html files, one option is to move all the content into a database and generate pages dynamically. However, migration to a database can be a time-consuming task depending on the volume of content. So wouldn't it be easier to somehow import the relevant parts of the existing html pages into your aspx page?

Getting various bits of URL with C#

calendar_today 27 April 2007 21:49

C# ASP.NET 2.0

Need some bit or all of the URL for any reason?

Parameter Queries in ASP.NET with MS Access

calendar_today 13 April 2007 22:17

ASP.NET 2.0 MS Access ADO.NET

A selection of code samples for executing queries against MS Access using parameters.

Paging long articles in ASP.NET using C#

calendar_today 09 April 2007 21:44

C# ASP.NET 2.0

Long articles are better broken into bite-sized chunks over several pages. With static HTML, this is easily achieved by dividing the article into logical separations and creating separate .htm files for each. Here's how to do it using C# for an article that gets posted to a database.

Date Formatting in C#

calendar_today 08 April 2007 21:11

C# ASP.NET 2.0

Cheat sheet detailing formatting options for dates and times in C#.

Migrating from Classic ASP to ASP.NET - equivalent objects and classes

calendar_today 07 April 2007 10:01

Classic ASP VBScript ASP.NET 2.0

Having spent some time familiarising oneself with the objects available in Classic ASP, it can be tricky sometimes to find the .NET framework equivalent. Here's a guide.

How to retain carriage returns or line breaks in an ASP.NET web page

calendar_today 06 April 2007 19:55

C# ASP.NET 2.0 HTML

Many newcomers to web development cannot get their head around why the carriage returns they made in their data on input from a textarea, or from a text file, Excel spreadsheet etc. do not appear when the web page renders.

Create an RSS Feed In ASP.NET 2.0 C#

calendar_today 05 April 2007 22:37

C# ASP.NET 2.0

Using the XmlTextWrite to output an XML file that serves as an RSS feed.

How to conditionally show an image, or other control in ASP.NET

calendar_today 04 April 2007 21:45

ASP.NET 2.0

Quite often, you want to display an item from a database that may or may not have an associated image. Examples might include a news story, product details, car for sale etc. But you want to avoid the dreaded "redex" if a picture isn't present.

Create A Utility Class Containing Site-Wide Functions

calendar_today 03 April 2007 21:33

C# ASP.NET 2.0

In Classic ASP, the typical model for managing site-wide functions is to create one or more server-side includes containing libraries of code. The OOP nature of ASP.NET offers a much more elegant solution.

Iterating through CheckBoxList To Insert Records

calendar_today 03 April 2007 20:52

ASP.NET 2.0 ADO.NET

Having inserted a record, you want to retrieve the newly created record's ID number, then iterate over a collection of items, such as a CheckBoxList to insert additional information relating to the record.

Insert Single Value With Stored Procedure ASP.NET C#

calendar_today 03 April 2007 14:16

ASP.NET 2.0 SQL ADO.NET

Code for calling stored procedure in the Code-Behind to insert a single value from a text box.

How can I use ASP.NET to do the following

calendar_today 01 April 2007 16:10

ASP.NET 2.0

A list of common things that people want to be able to use ASP.NET for on the client-side.