Archive for the 'ASP.NET' Category

System.Data.OleDb.OleDbException: Unspecified error

March 17th, 2010

I ran across this error in an ASP.NET project that was using ADO.NET to access the data in a .csv file (more info here). After much gnashing of teeth, I finally ran across this blog post, that explained the problem and provided a link to this MSDN article.
Basically, you need to make sure that the [...]

Use HttpModule to turn tracing on via the querystring

May 18th, 2009

Sometimes I want to turn tracing on in a production application to troubleshoot issues that I can’t replicate on my development machine.  It’s easy enough to do this by turning on application-level tracing in the web.config file, like so:
<configuration>
 <system.web>
  <trace enabled=”true” pageOutput=”true” />
 </system.web>
</configuration>
The problem with this is that changes to the web.config file cause the app domain to [...]

Get Max Number from Datatable using the Compute method

July 9th, 2008

This is a nifty little thing I came across recently.  I wanted to get the maximum value of a number field from a datatable, and learned about the Datatable’s Compute method.  It’s really easy to use.  The method takes two arguments – an expression argument, which is the aggregate expression you want to use (Count, Max, [...]

Gridview cell text values all Empty Strings

July 1st, 2008

I spent a good part of today butting up against this problem – puzzled and Googled and experimented and Googled some more, but could not for the life of me figure it out – I kept doing exactly what the examples said I should do.  But then I finally found the answer, and so thought [...]

Use Generic Methods to create a Session Wrapper class

December 26th, 2007

Getting values out of session in ASP.NET can be a bit of a pain for two reasons:

You have to remember what you named the value when you put it in
You have to type cast the value, as session stores it in an Object

One nice way to handle this is to build a wrapper class to [...]

Dynamically change Master Page body tag

December 19th, 2007

Today I spent several hours butting up against this, and finally, after much gnashing of teeth, found this great blog entry explaining what I needed to know.
Basically, the problem is that I needed to call a javascript function onload in the body tag of the page, but of course in an ASP.NET Content page there [...]

Pass multiple strings to stored procedure IN statement using XML

November 5th, 2007

(Revised 3.18.08)

Let’s say you have a listbox with multiple items selected, like this:And let’s say that you want to take the selected items and send them to a stored procedure to run in an IN statement in the WHERE clause, like this: SELECT * FROM tblProjects WHERE ProjectCity IN (‘Lewiston’, ‘Portland’, ‘Spokane’)
Turns out it’s not [...]

Determine Previous WizardStep using Wizard’s GetHistory Method

October 29th, 2007

Recently I was working on a project that contained an ASP.NET Wizard Control. The control was configured to allow non-linear progression through the WizardSteps. I realized that I needed to know which step the user had been on previously, as that would determine which control would have focus in the current step.
So [...]

Recursive method to reset controls in a ControlCollection

June 15th, 2007

This is a shared public method used to recursively interate through the controls in a control collection and set specified controls to an empty or unselected state.
First, I build two private shared helper methods to deal with an individual control. The first one checks to see what kind of control it is:
‘Helper function to [...]

Using System.Net.Mail namespace to send email

June 6th, 2007

Here’s a little demo of how to use the System.Net.Mail namespace to have your application automatically send an email. This sample is a class method that sends an email notification to the developer/webmaster/website owner/whoever when a new user registers on the site.
First, some set up. I keep the values for the From email [...]