One control – Multiple Validators

You can include multiple validators on one control. For instance, let’s say you have a TextBox for users to enter an email address. First off, you want it to be required, so you use a RequiredFieldValidator. But, also, you want to make sure you have an email address that is in the correct ‘email’ format.

Therefore, you can include a RegularExpressionValidator to validate the input, to make sure it is in the correct format, before it’s submitted via the form. In both instances, the ControlToValidate can be the SAME TextBox – no problem!

Iterating Through Rows of a DataTable Part II

To see another way of iterating through a DataTable, go to:
Iterating Through Rows of a DataTable

But, sometimes, instead of having the luxury of creating the datatable, you already have a dataset created and you need to iterate through the rows of the table in that dataset. Here’s how you do it -
First, globally create the DataSet if you haven’t already done so, along with creating a global variable for a DataTable (like: dt)

Dim dt as DataTable

Then, right after the DataSet is filled, assign dt to the Table in the DataSet:

dt = ds.Tables(0)

All you have left, then, is to iterate through the Table, doing whatever parsing you need:

Dim i as Integer For i = 0 to dt.Rows.Count - 1 if ds.Tables(0).Rows(i)("Fieldname") = (whatever) then ' Parse/build your results here End If next i

Using a UDL for a Connection String

If you have a common UDL for data connections that you use throughout your applications, you can use it very easily in ASP.Net

First off, like other connection strings, just store it’s path in your Web.Config file:

Then, in your page, define your connection string like this:

Dim strConn = "File name=" & ConfigurationSettings.AppSettings("My-UDL")

One last thing – it doesn’t matter whether or not you’re using a SQL Server or not – you must use the OleDb Namespace. Change your SQLCommand to OleDBcommand, etc…..

That’s all there is to it!

Removing the Last Character from a String

Scenario:
You have retrieved a list of items/data from a database, creating a string.
After each item, you have added a comma, or maybe a semi-colon. This presents a problem, since that
means there is one un-wanted character at the end of the string (let’s say we’ve dimmed the variable as
‘sList’

To remove that last character, let’s create a function called ‘Killending’:

Function KillEnding(sItem as String) Return sItem.Substring(0,sItem.Length-1) End Function

To use this in our scenario, we’d do it like this:

sList=KillEnding(sList)

That’s all there is to it!

Using OleDb With SQL Server

As many of you know, ASP.Net has a specific class (System.Data.SQLClient) to connect directly to SQL Server. This allows a much more efficient way to connect to the server. But that doesn’t mean its OleDb connectivity path has gone away – it’s still an OleDb compliant database. You can use OleDb, if the situation warrants it, by just changing the connection string to an OleDb compliant format, like:
“Provider=SQLOLEDB.1;Data Source=YourServerName;UID=sa;PWD=YourPwd;”

ASP.NET Session

ASP.NET supports Three types of session modes that are

1.InProc – In Process
2.StateServer
3.SQLServer
This mode is set in the Configuaration File

In InProc Mode….. Session Objects and Variables are keep in a Slot of Cache

When using StateServer u have to specify the IP address of remote machine
When SQLServer u have specify the ConnectionString.

that config file tag is

<sessionState mode="Off|Inproc|StateServer|SqlServer" cookieless="true|false" timeout="number of minutes" connectionString="server name:port number" sqlConnectionString="sql connection string" />blockquote>