Multiple Select Results in ASP.Net

In our new ASP.Net app, we are using one list box that allows multiple-select. Recently, choosing one of the items in the list produced no results. But items would not be in the list if there were no results, so there must be a problem in the SQL statement related to the multiple-select list or the data.  In classic ASP, you would access the multiple items like this:

    Request.Form(i)(j)

where i is the form item and j is the result of the multiple-select. Unfortunately, that does not work in ASP.Net. If you access the form item directly in ASP.Net, like this:

    Request.Form(i)

it provides a comma-delimited list of the multiple form items. It's pretty easy to then split the list on the commas, and that was what we were doing. Ahh, the bad item in the list had a comma embedded in its text. So it was splitting inappropriately and creating a bad SQL statement for fetching results. This was the source of the problem here. There must be a way to access the items individually, but it was not obvious to me. I must have stared at the MSDN docs forever trying to find the answer. I had to try three or four different keyword searches on Google before I found an excellent explanation here.

The results of a mulitple-select list are also a NameValueCollection, just like the Request.Form. Once I found that, it was easy to get at the individual items. The entire collection is accessed like this:

    Request.Form.GetValues(i)

and the individual items are accessed like this:

    Request.Form.GetValues(i)(j)

I was really surprised at how difficult it was to find this information. Both of my favorite ASP.Net books, Essential ASP.Net by Fritz Onion and Programming ASP.Net by Dino Esposito both had no mention of the embedded NameValueCollection. This seems like it would be a common problem for developers using forms, but I did not find the answer to be as obvious.

Posted: Friday, November 14, 2003 1:22:40 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 1.1 | ASP.NET

Temporary Tables in Oracle8i

Our application uses some fairly complex PL/SQL procedures to build reports in temporary tables so that we can access the data as a ref cursor and bind to a grid. We built the tables using “on commit delete rows” when creating the Oracle table. See DBASupport.com for a quick explanation of Oracle's temporary tables. But calling commit inside the PL/SQL package did not delete the rows as implied by the Oracle documentation. The new data on subsequent calls simply added to what already existed in the table. We are using an Oracle Provider version of the Data Access Application Block, and called the stored procedure like this:

DataResults = Daab.ExecuteDataTable(CommandType.StoredProcedure, ProcName, ProcParametersArray)

To solve the problem, we wrapped the call to the stored procedure in a transaction, even though the procedure only issued select sql statements.

Dim FakeTransaction As OracleTransaction

FakeTransaction = Conn.BeginTransaction(IsolationLevel.Serializable)
DataResults = Daab.ExecuteDataTable(FakeTransaction, CommandType.StoredProcedure, ProcName, ProcParameters)
FakeTransaction.Rollback()

Oddly enough, calling .Commit() did not work as implied by the “on commit delete rows“ command added when creating the table. The data persisted in the table. Calling .Rollback() worked though, as I would expect for any transaction. I was unable to find documentation to tell if there is any perfomance drawback to using IsolationLevel.Serializable versus IsolationLevel.ReadCommitted or IsolationLevel.Unspecified as all three give the desired effect on the temporary table.

Posted: Tuesday, November 04, 2003 7:06:10 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 1.1 | ADO.Net

.Net Jobs

The October issue of Dr. Dobbs Journal has a small article called Quantifying Popular Programming Languages. This article is unfortunately not available on-line for free. Dr. Dobbs surveyed web-based job boards to see what percent of the job postings contained references to specific programming languages, but they did not divulge which boards they surveyed. The survey lasted from July 2002 to June 2003. Only 16.4% of the jobs posted contained references to .Net, 5.35% mentioned VB.Net specifically, and 5.16% mentioned C#.  Java ocurred in over 40% of the ads and C++ was in over 50% of the ads. Visual Basic was in 19.2% of the ads. Does this reflect a slow adoption of .Net? Or is this just an effect of the economy, or both? I have lurked around the MCAD usenet group and seen frequent comments about the lack of jobs specfically for .Net. Of course, my company is certainly not hiring (see my post here), and the project I am on is the only .Net project in the company. In my experience the benefits of .Net development are significant compared to what we were doing in the past, even for the customer. Are we just not getting through to the business decision-makers about where we need to go? Or should I really spend more time learning C++?

Posted: Wednesday, October 15, 2003 6:57:28 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
None

OS = Windows 98

In response to: http://dotnetjunkies.com/WebLog/donnymack/posts/2383.aspx

 You are Windows 98.  You're a bit flaky, but well-liked.  You don't have a great memory, but everyone seems to know you.  A great person to hang out with and play some games.
Which OS are You?

Posted: Thursday, October 09, 2003 4:55:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
None

Business Objects Dead?

There a fascinating discussion going on at Tim Sneath's blog about the functionality of the business layer moving to compiled stored procedures in Yukon. At least in my project, we have been doing that very thing and struggled with the n-Tier issue as a result. In our case, the database is Oracle 8i, and the application is/was ASP, which we are now converting to .Net. We have some very complex business logic encapsulated in PL/SQL stored procedures. There were two concrete reasons for the decision:

  1. The amount of data that would need to be transferred was huge.
  2. Oracle is more efficient than ASP code at many of the operations involved.

With ADO.Net, some of the ineffieciency may be addressed, but the database is designed for efficiency at certain operations that ADO.Net won't be able to match.

We did not need to approach this from a scalability issue, as the app receives hundreds of hits per hour, not thousands or more. I still think it will scale OK as your business objects will have much shorter life spans and you can still pool and queue database connection objects if needed due to long-running stored procedures.

Posted: Monday, October 06, 2003 12:57:15 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Programming

Very Long Week

My company just spent 3 days laying off tons of people. I survived this round, but the development group I am a part of lost three people. The company was about 8000 people worldwide, I wonder what it is now. Management is not interested in distributing the details. It's pretty rough watching the CIO follow around the HR team that is laying people off, and then getting to listen to them cleaning out the cube on other side of the wall.  I am fortunate to have a good project that lets me learn .Net. If my turn comes at least I am acquiring new skills.
Posted: Friday, September 26, 2003 12:23:27 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
None

Data Access Application Block and Oracle

I read about the Data Application Block yesterday and was intrigued, although for the life of me I cannot remember where I read about it originally to pass along some credit. So I checked it out and it is very nice and all, but alas my project uses Oracle not SQL Server. Initially I thought about porting it to Oracle, but I figured that it has already been done. So I did a little Googling and voila!, Microsoft themselves had already done the work in the Nile 3.0 demo application. Sadly, it was in C# and my current project is using Oracle and VB.Net. So now I am back to porting.

Posted: Friday, September 19, 2003 12:43:39 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 1.1 | ADO.Net | Oracle

Query a Novell LDAP server with VB.Net

Once again, I am amazed at how simple tasks have become using .Net. Something I thought would be complex turns out to be completely handled by the framework. Kudos to the .Net team.

For my current project, I need to validate that a person is an internal employee before allowing them continued acccess to the web site. My company uses a Novell infrastructure, and luckily has an LDAP server that I can access for employee validation.

Luckily, Novell provides a resource for developers to begin working with LDAP at the Novell Developer Labs. You can create an account and query their server for free. So that is where I started, but eventually the Novell network admins in my company got around to my request and I was able to use the code almost without modification against our internal server.

Here is my quick console application I created to test against the Novell Developer Lab LDAP site (my container name is Fender and my login is admin.  The only modifications I had to do to get it to work with my company's LDAP server was to learn the container names and the fields I could query.  

Imports System.DirectoryServices

Sub Main()
Dim
ds As New DirectorySearcher
Dim resultset As SearchResultCollection
Dim result As SearchResult
'Return the securityEquals field and the cn field
Dim ResultFields() As String = {"securityEquals", "cn"}

With ds
    'Set the container I want to search (.admin.Fender.user.novell)
    .SearchRoot = New DirectoryEntry(
LDAP://192.108.102.215/ou=Fender,ou=user,o=novell)
    'Use the array set above for return fields
    .PropertiesToLoad.AddRange(ResultFields)
   
'Set a filter/query
    .Filter = "cn=ad*"
End With

Try
  
'Perform the search

   
resultset = ds.FindAll()
    If resultset.Count > 0
Then
       
For Each result In resultset
            Console.WriteLine(result.Properties("securityEquals")(0))
       
Next
    Else
        'No results
       
Console.WriteLine("No Data Found")
    End If

Catch ex As Exception
   Console.WriteLine("Error: ")
   Console.WriteLine(ex.Message)
End Try

End Sub

Posted: Friday, September 12, 2003 2:43:44 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 1.1 | Novell | Security