Saturday, July 28, 2007

Importing/process a CSV File in VB.NET

Some us developers love doing is data imports :P Even more so when it's CSV or worse still, fixed length fields!! :P Thank goodness VB.NET gives us the StreamReader which allows us to open a file with a single line of code, thanks to the constructor overload. This also allows us to trip through the file line by line by calling the read method and also returning False when it is EOF!! What's more we have the split function on the string to chop it up on any delimiter of our choice and push it into an array!! What more could we ask for! So here is the code snippet:
Dim sr As New System.IO.StreamReader("mycsv.csv")

Do While sr.Peek <> -1
Dim myflds() As String
Dim myline As String
myline = sr.ReadLine
myflds = myline.Split(",")
' now you have every field in a sep element array
' Push them into a db, whatever


Wednesday, July 25, 2007

Enabling ASP.NET 2.0 extensions on Windows 2003 Server

Whilst testing a clean installation of Win2K3 Server with IIS, SQL server 2005 and VS 2005 I tried to create a new ASP.NET project in IIS and got the following error:

Microsoft Visual Studio
Configuring web site 'http://localhost/WebSite' to ASP.NET 2.0 failed. You may need to manually configure this site for ASP.NET 2.0 in order for your site to run correctly.
OK Help

The problem is that ASP.NET extensions are prohibited from running on your computer by default. This is part of Microsoft's drive towards security by default (i.e out of the box). However it is easy to enable it by following these steps if you are working on Windows Server 2003
1. Open IIS Manager (open Run dialog from Start Menu and type 'inetmgr' in Start Edit Combo Box).
2. In the IIS manager window, expand the Local Computer node.
3. Click on Web Service Extensions node.
4. Allow "Active Server Pages" and "ASP .net v2.0.xxxxx".

Thursday, July 19, 2007

ALT Keycodes for Euro symbol and @ sign

I had a keyborad go crazy in a class today and needed a work around quickly :) For some strange reaon the @ symbol was not working inside the virtual machine!!! I had just had a request for the ALT code for the Euro symbol only a day before and found this link most helpful:

Just to summarise:
ALT + 0128 = €
ALT + 0064 = @

ALT + 0169 = ©

(NB. These have to use the left ALT key and the NUM KEY PAD. Can anyone tell me how to do this on a laptop without getting youyr fingers in a twist!!)

Wednesday, July 11, 2007

Get the current selected row in VB.NET DataGridView

Something that gets asked often in the forums is:
'How do I get a hold of the currently selected row in a datagridview?' so that I can pick a particular cell and manipulate it, use it for a calculation etc.

The trick is knowing that DataGridView1.CurrentCell will tell you the cell the user chose.
So if we ask for the Rowindex like this:

Then we can combine it with the Datagridviews rows collection to index just that row, like this:

We can take this further to drill into a column in that row by accessing the rows cells property like this:
DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells().Value += 1

Saturday, July 7, 2007

Wireless Presenter Notebook Mouse 8000

OK so secretly I'm a bit of a hardware/gadegt junky, but this something I could really use (hint, hint for Christmas please, since I can't wait until my birthday) I really like the laser pointer, good for lectures/training. But the media Center edition controls make me feel like I'm on an i-Mac :) Take a virtual tour here.