.Net ramblings
# Monday, 24 May 2004
Environment.SpecialFolder enumeration not showing up in Visual Studio Intellisense

I was using an OpenFileDialog and i wanted it to open at the My Pictures folder for the current user.  So i looked up the msdn docs for how to locate this folder, and i come across the Environment.SpecialFolder enumeration, which has an entry for MyPictures.  Great, my code then was:

this.openFileDialog1.InitialDirectory = Environment.SpecialFolder.MyPictures; 

but this didn't compile, and it didn't show up in Intellisense.  I read a few examples online which used the following syntax:

this.openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); 

and it worked, although it still didn't show up in Intellisense.  you'd think MS would at least explain this in the docs, weird.

Monday, 24 May 2004 12:34:15 (GMT Daylight Time, UTC+01:00)  #    Comments [1]  .Net Windows Forms

# Saturday, 17 April 2004
Use a HOSTS file to block banner ads

You can use the HOSTS file in Windows to prevent banners from displaying in web pages.  It is usually in c:\windows\system32\drivers\etc. Note that it has no file extension. There are a few good sample files online that contain thousands of known advertisers.  I use http://everythingisnt.com/Hosts as a reference.  If that link is down, use my mirror copy (29 k).  The way it works is by redirecting the url (e.g. ad.doubleclick.net) to your own computer, instead of the proper doubleclick.net server.  Your local web server (if you have one) won't contain any of banner images or pages requested and you see a 404 page not found in the browser in place of the banner image / web page.

Saturday, 17 April 2004 17:53:23 (GMT Daylight Time, UTC+01:00)  #    Comments [1]  General

# Saturday, 03 April 2004
ADO.NET parameter quirks with ODBC and OleDb

The OleDb Provider

If anyone is using the Oledb provider with .Net, when you are adding parameters to an OleDbCommand in code, make sure you add them in the order that they belong in the sql string. 

For example, if your sql string is:
"insert into table1 (username, password) values(?,?)"
and you have parameters added to the command (usually done through a configure OleDbDataAdapter wizard), called "@Username" and "@Password".  Your code must add the parameters in the correct order as follows:
this.oledbCommand1.Parameters("@Username").Value = username;
this.oledbCommand1.Parameters("@Password").Value = password;

If you don't do it this way, you may get a jet error: "No value given for one or more required parameters.". 

This quirk does not apply for the Sql provider in ADO.NET, because you can name the parameters in the sql string, e.g. 
"insert into table1 (username, password) values(@Username, @Password)"

The ODBC Provider

If you're using the ODBC provider with .NET (probably for MySQL), there is one oddity that you should know about too.  In sql strings for odbcCommand objects, you can't use the @ParamName syntax.  You have to use question marks as placeholders for the parameters as follows:
"insert into table1 (username, password) values(?,?)"
Similarly, you have to add the parameters in the right order. 

Saturday, 03 April 2004 18:07:08 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  Database

# Thursday, 01 April 2004
Working around DVD install problems. Use Xcopy instead...

when i was building my computer, i got a cheap DVD drive, and i'm paying for it now with trouble installing any of the software that came on DVDs with my MSDN subscription.  I tried installing Windows Server 2003 from the DVD by booting straight from the CD but it failed at different stages, saying file not found, or corrupted files etc.  I'm convinced its because of the quality of the dvd drive.  To be safe, I now copy all the files to the hard drive and then install from there.  Even copying the files to the harddisk through Windows was not trivial as ms point out in http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318945, they recommend using the xcopy command to verify that the files are copied correctly. The copy speed with xcopy was several times faster than using windows explorer, I have no idea why, but i always do it that way now. The syntax is:

xcopy <source> <destination> /V /H /Y /E

e.g. (from the command prompt. Start > Run > cmd.exe)
xcopy E:\VS2003\ C:\Local\VS2003 /V /H /Y /E

The switches mean:
/V = verify
/H = hidden files
/E = sub folder including empty folders
/Y = suppresses prompting to overwrite

Thursday, 01 April 2004 15:25:50 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  General

# Friday, 26 March 2004
Micorosft Empower Program, the motivation behind it...

My application to join the MS Empower Program for ISVs was accepted this week.  The first thing I did was go straight to the MSDN download section and drool over all the software now available to me to download.  (Shame I'm on 56k... oh eircom get your act together and deliver broadband soon, it's not like I live in the sticks or anything <moan moan>)

For a €375 subscription fee I get the equivalent of €30k worth of software, of which I will realisitically only use a few thousands worth, but still, how bad.  There are a few costs associated with it, like a software verification test, digital ID from Verisign etc. but it's still a great deal, and actually the cheapest way for me to start using Visual Studio 2003 architect. 

I sat today wondering why MS are acting so desperate to get ISVs like me to write software for .Net in particular.  Then it struck me... (a rare moment of mental clarity), and I remembered back to what a man was saying at a Longhorn conference I was at earlier in the year.  He said that Windows Longhorn will run with 2 kernels, one for Win32 apps and a new kernel for apps written in .Net, i.e. managed code.  This is obviously great for backwards compatibility, with the advantages being given to new applications with the new kernel.  BUT... what if .Net apps don't become mainstream for 5 or more years?!  the new kernel will be more or less unused and we might as well be running a souped up XP pro instead.  Avalon, the new user interface, will also only work with .Net apps (.Net 2.0 at that), and other apps will look the same as XP.  It is no wonder MS are not giving a solid release date for Longhorn, since I reckon it depends on the take-up of .Net software.  If it is great, they will push to release longhorn early to give users the advantages of running .Net apps on a managed operating system.  But if it is slow, they will throw more and more resources to the developers and software companies in programs like Empower for ISVs until the knock-on effect of that is to put a whole lot more .Net software in to the marketplace until .Net becomes the standard. 

Here we are 2 or 3 years into the launch of .Net and most people around here still think it's bleeding edge technology if they have heard of it all.  (Yes there is a modern side to Ireland, but a lot of it is still running Windows 95, that's the reality of the environment we are building software for).

Something about knowing that my apps will one day execute in a managed Kernel in Longhorn really gets me going :) but i think it might be longer than MS think before it becomes the norm.

Friday, 26 March 2004 23:57:16 (GMT Standard Time, UTC+00:00)  #    Comments [3]  General

# Tuesday, 16 March 2004
Howto: use MySql with .Net

MySQL is a great alternative to SQL Server because it is open source and nearly has the performance to rival SQL Server. Applications using Microsoft Access databases can suffer seriously if the transaction load is anything above minimal. This article is my collection of instructions and tips for getting up and running with MySQL and .NET.


  1. Download & Install MySQL 4.0 (16 Mb)

  2. Download & Install ODBC.NET Data Provider (800 k)

  3. Download & Install MyODBC 2.5 (1.5 Mb)
    Note: the newer versions do not work with .NET at time of writing

  4. Optional: Download & Install DBManager, GUI for MySQL tables, highly recommended (3 Mb)


  • Make sure the MySQL service is running in Windows.

  • Load up the WinMySQLAdmin.exe tool in the bin folder of your MySQL install. This program controls the MySQL server. Feel free to customise any settings you wish, e.g. change the Server Name, Port Number, username & password etc.

  • Load up DBManager and connect to the Server. The default user is root with a blank password. You can create your own users or keep using the root. Create a test database and then right-click the 'Tables' node under the database you just created. Use the 'Table Editor' to define the fields for the table. Click the 'Save' icon to save your changes. Users from MS Access backgrounds may want to read below.

To connect to the database through .NET code:
Add a reference to Microsoft.Data.Odbc.dll, this should be in 'C:\Program Files\Microsoft.NET\Odbc.Net'

using Microsoft.Data.Odbc;
string sql = "select * from table1 where ShortName = ?";

// declare an OdbcCommand object with a new OdbcConnection
OdbcCommand command = new OdbcCommand(sql, new OdbcConnection(connString));
// add a paramter to the command corresponding to the ? in the sql statement
OdbcParameter dbParam = new OdbcParameter('ShortName", OdbcType.VarChar, 50);
dbParam.Value = "bob";

DataSet ds = new DataSet();
OdbcDataAdapter dba = new OdbcDataAdapter();
dba.SelectCommand = command;
catch(Exception ex)
  throw ex;

Unfortunately, MS never provided OdbcDataAdapter & OdbcCommand GUI support for Visual Studio so you have to do all that manually, as in the code above. However, there are commercial components that solve this.

The 'System Error' ODBC message
If you get a 'System Error' message thrown in your code using MySQL, with no useful information, you need to catch the line of code causing the error and throw the exception explicitly (i have no idea why, but MS have a kb article about it).

Note on DBManager Queries
This version of MySQL doesn't support Stored Procedures, but you can still save queries to the database. Click the 'Create new query' button in DBManager and enter the SQL you want. There is a query designer but the intellisense doesn't work well and it can be annoying to use. Save the query and it appears as an extra tab after 'DataSheet' in the lower right corner. When you close DBManager, next time you open it, that tab won't be there and it will look like the query was only temporary. They are actually stored permanently, and accessible via the 'Tools' tab on the lower right of the screen.

Notes on the MySQL field types for anyone from an MS Access background

  • MySQL uses the single apostrophe character for quoting values, e.g. select * from table where name = 'bob'. the double quote character causes a syntax error.
  • there is no 'bool' field type as such, use 'TinyInt' and change the size to 1 bit, then use 1 to represent true and 0 for false.
  • the varchar field type is limited to 255 characters, in MS Access you would use a Memo to go beyond this. MySQL has the tinytext, mediumtext and longtext field types to support larger max characters.
  • to force the input to match a list of values, e.g. Categories: Animal / Vegetable / Mineral, use the 'Set' field type, with comma separated values in single quotes: 'Animal', 'Vegetable', 'Mineral'
  • the 'Now()' function is supported in MySQL as a default value for a DateTime or Date field, but when you enter this in DBManager, the value appears as 0000-00-00 00:00:00 in the Table Editor, this seems unusual but the function works as expected.

BTW, if you're looking for .NET web hosts that support MySQL, check out www.webhost.ie

Tuesday, 16 March 2004 23:27:39 (GMT Standard Time, UTC+00:00)  #    Comments [0]  Database

Problem setting text for a password asp.net textbox

This short article outlines a quirk of the textbox control in Asp.Net, when set to password mode.  If you try and use myTextBox.Text = ….; it doesn't happen.

You might want to use something like this if you are presenting users with the facility to change a password, and you want to give them the option of changing their password, shown in stars, by simply deleting the stars and typing in a new one.  To accomplish this, use the following syntax:

myTextBox.Attributes("Value") = someString;

I can't think of a good reason ms built it this way at all.  oh for .net 2.0...

Tuesday, 16 March 2004 23:06:12 (GMT Standard Time, UTC+00:00)  #    Comments [0]  Asp.Net

# Monday, 15 March 2004
Windows Forms DataGrid throwing a null reference exception on DataRowView.CancelEdit()

I encountered a frustrating issue using the Windows forms Datagrid today.  This problem was also posted without reply on an ms newsgroup. I'm posting my work around here for the record. 

Problem Description
My windows form had a tabcontrol, with 2 tab pages, each with a datagrid, bound to a table in a dataset.  The problem occurred when the user switched from the second tab to the first, with the last row of the datagrid being left as a new row with default null values. It was in 'edit mode' usually because the user added a new row, or pressed enter, which automatically places the cursor in another empty new row, with the default values. The exception I got was generated by the framework and not from my code, as follows:

Object reference not set to instance of an object, at:

System.Data.DataRowView.CancelEdit() at
System.Windows.Forms.CurrencyManager.CancelCurrentEdit() at
System.Windows.Forms.DataGrid.OnLeave_Grid() at System.Windows.Forms.Control.InvokeMarshaledCallbacks()

The exception is interesting in that the CurrencyManager kicks in when the focus of the DataGrid has left, and cancels the cell currently being edited. 

I tried several solutions, and eventually worked around the problem by forcing the user to click a button to switch from one tab to the other (I hid the tab change buttons off the screen), and then disabling whichever grid wasn't being used after the button was pressed.  This seemed to change the way the DataGrid cancelled the edit of the last row, and the exception doesn't happen now.

It's not an elegant solution, so I'm open to suggestions. I do think the datagrid should be able to execute CancelCurrentEdit without throwing exceptions, and I would be interested to understand why it happens.  I guess it will be fixed in .Net version 2.

Monday, 15 March 2004 19:12:33 (GMT Standard Time, UTC+00:00)  #    Comments [2]  .Net Windows Forms

# Saturday, 13 March 2004
Howto: configure a Psion Series 5 for internet access with a Nokia 6610 (GPRS)

This took ages to figure out, and plenty of experimenting with different settings, so hopefully this might save someone else the hastle of having to spend half a day to get their Psion 5 (not MX) connected to the net with a Nokia 6610.  I would say it would work with similar settings on other GPRS phones.

The internet settings are for the O2 network in Ireland and will need adjustments for a different network.

  1. install Psion Series 5 Message Suite version 1.52.
  2. Create a new modem called nokia 6610:
     speed 57600
     connection infrared
     fax class auto,
     init string: ATZ
     flow control: hardware (RTS/CTS)
  3. Create new Internet Service called GPRS with the following settings.
     connection type: dialup
     uncheck smart dialing
     standard dial-up number: *99#
     manual login unchecked
     username gprs 
     password gprs
     addresses: get IP from server. get dns address from server unchecked.
     primary dns address:
     secondary dns address:
     login: use login script checked. default 8 bit no partity 1 stop bit,
     delete all content of login script text box, leave blank.
     advanced: enable PPP extensions checked. allow plain text authentication checked.  
  4. On the psion, set Remote Link to Infrared 57600.
  5. Get the GPRS settings for your phone from your network. O2 will send those details to your phone if you request it from http://www1.o2.ie/CM/getcontent/0,1177,txt_html_OTA_Home,00.html. Save these details to your phone.
  6. Activate Infrared on the phone. Connectivity > Infrared.
  7. Point the Infrared port of the phone thin black band on top of phone) to the Infrared port on the psion (1cm band on back of psion) a few inches away.

Saturday, 13 March 2004 23:10:23 (GMT Standard Time, UTC+00:00)  #    Comments [0]  General


Hi, welcome to my blog.  This is where I will post solutions to problems I encounter while writing software for the .Net platform, in the hope that they may be of some use to people trawling google for an answer to the same problem.  I realise that I wouldn't be half the developer I am today if it weren't for the likes of Charles Carroll's aspNG community, GotDotNet, ms newsgroups, asp.net, windowsforms.com, to name but a few.  I have drawn on these resources for advice and technical assistance many times and this is my way of returning some of that generosity to the community at large, (as well as a space for me to rant about stuff and things).

a little about me
I've been developing in .Net since Beta 2 in 2001 and I write in C#.  I did my undergrad in University of Limerick in Computer Systems, and now I am self employed, doing contracts, training courses, developing software, etc. in Limerick, Ireland.

Flying Simon's Super-10 kite at CastleGregory, Ireland 2002Outside work, I like surfing, table-tennis, flying big kites, cooking and other stuff, so from time to time, you may see the odd post that is nothing to do with .Net...

Saturday, 13 March 2004 19:12:01 (GMT Standard Time, UTC+00:00)  #    Comments [3]  General