Iterating Through Rows of a DataTable

Sometimes we need to look through a specific column in a datatable, in order to find a specific value. One way to do it would be to add all items together in one string and use a property of the String Class, called ‘IndexOf’. Here’s how to do that:

Dim MyTable as DataTable Dim sString as String Dim myRow as DataRow DA.Fill(MyTable) '0 then ' whatever you need here (you found 2)

To see another way of iteration, click here

Could not find installable ISAM

If you are using the OleDb Managed Provider, and you get this error, double check your connection string, to see if everything is spelled correctly. For instance, if you use ‘DataSource’ instead of ‘Data Source’, or misspell any other key words in the string, you will get this error.

Also – when all else fails, check out this MS link:
http://support.microsoft.com/?scid=kb;EN-US;209805

Adding a 'Friendly' name to an Email Submission

Adding a ‘Friendly’ name to either the ‘To’ or ‘From’ properties, in an ASP.Net form submission is fairly painless.

The format is like this:

objMail.To="Friendly Name <whoever@wherever.com>

Naturally, this applies for the ‘To’ and the ‘From’ properties. In addition, you can use dynamic email addressses like this:

objMail.To="Friendly Name <" & sEmail & ">"

And, finally, you can use a dynamic Email address along with a dynamic Friendly name like this:

objMail.To=sFriendlyName & "<" & sEmail & ">"

Request Validation – New Feature in v1.1

If yu have forms which allow HTML input, and you upgrade from ASP.Net 1.0 to 1.1, you will probably find an error you hadn’t encountered before:

"A potentially dangerous Request.Form value was detected from the client..."

This is a newly added security feature of v1.1.

It can be disabled, however, if you are sure of the security of your form. A good representation of this is the form used to add tips on this web site. All tips go through an authorization process – the input is checked out and verified before it goes live.

In situations like these, you can disable it by adding this to the Page Directive:

validateRequest="false"

You can also add it into the Web.Config file, to disable it for your entire application:

<configuration> <system.web> <pages validateRequest="false" /> </system.web> </configuration>

Naturally, this is normally NOT a good idea, unless you have security measures installed that would prevent damaging input.

Also, you can use ‘Server.HtmlEncode(<Data>)’ to Encode the data as it’s inserted into the table and then, Decode it, when you’re displaying the data.

More information can be found here:
http://www.asp.net/faq/RequestValidation.aspx

Adding a MailTo Link inside a DataGrid

Suppose you have a database table which contains an email field, and you’d like to display that field, as well as others in a DataGrid. Let’s go one step further – - let’s say you’d like to display that email field as a clickable MailTo link. One way that this can be easily be done using TemplateColumns. First, you create your DataGrid start and end tags. Then, inside these tags, you include ‘Columns’ start and end tags. That’s where you put your TemplateColumn. Here’s how to do it:

<Columns> <i>.....Put any other boundcolumns you want inside here also</i> <asp:TemplateColumn HeaderText="Email Address" HeaderStyle-Font-Bold="True"> <ItemTemplate> <A HREF="Mailto:<%# Container.DataItem("email") %>"> <%# Container.DataItem("email") %> </a> </ItemTemplate> </asp:TemplateColumn> </Columns>

MS Access Update Problems with Parameters

A very common problem, using parameters with MS Access, in ASP.Net is that it does not update the database, but also, it doesn’t return an error. The problem, most likely, is that the parameters are not in the same order as the SQL statement.

Remember to put the list of parameters in the same order as they hold sql statement, including any parameters in the Clause(s) at the end of the statement.

Show DataGrid Page Numbers only if Pages >1

When using DataGrid paging, it seems rather ludicrous to show the ’1′ in the Pager Section, if there is only one page. However, you can get around this. First – do not set ‘Paging=True’ in the DataGrid tag itself.

Second – check the number of rows in the returned DataSet. If the number of rows is smaller than, or equal to the PageSize number in the DataGrid tag, set the ‘AllowPaging‘ property of the DataGrid to ‘False‘. Otherwise set it to ‘True.


If DS.Tables(0).Rows.Count <= MyDataGrid.PageSize Then      MyDataGrid.AllowPaging = False Else      MyDataGrid.AllowPaging = True End If

Check for Null before inserting into Database

Here’s a function to ensure a Null value gets inserted into the database.

Function CheckForNULL(strStringToCheck) if len(trim(strStringToCheck)) = 0 then CheckForNULL =dbNull.Value else CheckForNULL = strStringToCheck end if end function

If you have a DateTime field, without a function like this, a default date will be entered (ie 1/1/1900 12:00:00 AM), instead of null, when your insert is executed.