Binding and DetailsView

Since I’m doing more ASP.Net than I’d normally like to admit to, here’s a really useful little snippet that I struggled with earlier. After my google ninjitsu failed me I turned to figuring it out for myself.

Once I’d wiped the sweat from my forehead I came up with a solution. Whew.

Ok, the problem was that I have a typical master/detail gridview & details view on a form which allows the user to select a row in the grid and then edit the details via the DetailsView. So far so good. I managed to get the whole thing hooked up declaratively using ObjectDataProviders so it felt almost like the XAML i know an love 😉

Anyway next on the agenda was the field validation. I’d re-templated the fields on the DetailsView so we’d got DropDownLists showing predefined lists take from the internal DataModel. Life was good. Throw in a few field validators and we’re good to go. Almost.

Since some of the fields on the form were just TextBoxes, I’d added the typical RequiredFieldValidator, but what about the lengths? These text boxes are mapped VarChar columns on the DB, they had an explicit length. I could hand code the length with the MaxLength property but that just means more work should the DB schema change on me.

If this were XAML we’d have it bound up in no time, but all my attempts in ASP failed miserably.

I know that the DataContext – oops sorry (!) – DataItem must be a DataRow from the table the grid was bound to, so there must be a property giving access to the rows columns. Sure enough, there’s the DataRows Table property we can use. Great! Saved! Effectively what I’d like to do would be bind up the MaxLength property to a DataColumns MaxLength propert. Sound simple. something like

<asp:TextBox MaxLength='<%# Table.Columns["GUR_FORENAME"].MaxLength >’>

Not so fast buster. Unfortunately  the above and all variations I tried didn’t seem to work. Even trying to Bind() to the table didn’t seem to work either

<asp:TextBox MaxLength='<%# (Bind(“Table”) as DataTable).Columns["GUR_FORENAME"].MaxLength >’>

Since Bind(“Table”) returns object, i thought i was in there! No such luck. Dozens of variations later, magic incantations, a full moon and some voodoo, I finally managed to get it working.

The final version of the binding expression I was after looked like this :

<%# Eval("Table.Columns["GUR_FORENAME"].MaxLength") %>

I’m still freaked out by the fact the whole expression has to be inside the quotes. If Bind() really does return an object what the hell is it? If I had time to spare I’d reflector through this, but unfortunately after spending too long on figuring out how to bind the max length, it’s something that will have to wait.

So, it looks like the ASP binding is a bit more flexible than first thought, and not surprisingly , the standard examples hint at!

Reblog this post [with Zemanta]
Posted in General | Leave a comment

Fix Oracle dot Net…

SAN FRANCISCO - SEPTEMBER 24:  The new Oracle ...

Image by Getty Images via Daylife

…is now up! FixOracle.Net in its first incarnation fixes the type of dodgy Oracle code we’re using on our current project, but since the ‘fixing engine’ is shared between the web site, the winform tool, and the command line tool, when I figure out what casts are missing, I’ll add them too.

In the mean time http://www.fixoracle.net is where you need to go for the absolute best in web design and hot advert-clicking-for-your-friends action.

Well, they’re not going to click themselves.

🙂

Reblog this post [with Zemanta]
Posted in Hackery | Leave a comment

Fixing Oracle’s TableAdapters

Ok, by now you know Oracles table adapters are broken. Just searching on google for a solution turns up a significant number of other people having the same issues. Broken code, bad ODP crashes inside devstudio etc etc etc. Google turns up nothing but bad news when you’re looking for a solution to ease the pain of using .Net and Oracle tools.!

Well, since the fixes are pretty easy to add, I’ve created a little tool to automate the process. Although the fixes are quite simple, they soon mount up when you got more than a couple of TableAdapters that change more than a couple of times during the life of the project. In fact fixing oracle’s bugs starts eating a significant part of your development time, beyond the most trivial projects with one or two adapters. Maybe we should start invoicing them for the time taken to fix their crap code 😉

ok, enough of the idle banter. Since a picture is worth a thousand words here’s a screen grab of the tool to whet your appetite!

orablefixer

Ok, I admit I stole the graphic! Basically this fixes the current crop of problems that the ODT generates when you drag a stored procedure or table to the VS’s Dataset design surface. As an additional ‘fix’ it also makes the Adapters CommandCollection public if you tick the check box.

Making the CommandCollection public means that you don’t have to derive a class from the generated table adapter, or provide another partial class when you want to do things like change the connection string on the fly, or make the commands participate in a transaction.

For those of us unable to use an ORM too or we’re just stuck with Oracle and the default tools for legacy code, this should help a little.

Anyway, I’m going to register a domain for the tool, and provide an online version too, where you upload a source file to fix, and it returns the fixed version. Maybe when there’s a public domain showing how to fix Oracle’s deficiencies, they’ll release a patch for a bug that’s been on metalink for what feels like *eternity*.

Watch out for FixMyOracle.Net coming soon 😉

Posted in General | Leave a comment

The Value of time revisited!

silver copy of a 1930 penny

Image via Wikipedia

After speaking to one of my friends about this, I must point out that my current client *IS* actually switched on enough to correct the situation by providing the best equipment they possibly could. It’s as pleasant change to have people in the chain who do value your time, and are more than willing to help remove any obstacles to you being productive. Although I did mention this in the previous post, it does read rather like they’re not paying attention, which they absolutely are.

My post was really about the real cost of loss of productivity and effectiveness in order to save pennies on equipment, where someone outside your project holds the budget, and thinks you’ll be spending 7.5 hours a day editing word documents and emailing.

Perhaps they should try creating a DocProject with half a dozen assemblies, and see how long it takes before they can use their PC again 😉

I’ve turned this type of semi-rant into a small essay, with references to various sources citing just the kind of point’s I’ve brought up here. I’m in the middle of reformatting it, and removing the names to protect the guilty. When that’s done I’ll post the whole article here for your viewing displeasure!

 

Reblog this post [with Zemanta]
Posted in General | Leave a comment

The value of time.

SyncMaster 152X is Samsung's 15

Image via Wikipedia

I’ll never understand how some people in IT departments don’t grasp the value of a developers time. Its a false economy to provide anything but the absolute fastest PC for a developer. I’m not really sure where the real problem lies. Is it that non-techie people rise to management positions without realising what precisely their reports are doing?

Take the current client. We’re working on incredibly old PC’s – P4’s with 2gb of ram and 40gb.  DevStudio is simply un-useable. I don’t care what the minimum supported spec says, it’s painful. We’ve managed to get some new PC’s ordered, but in most other places its simply not that easy. We still have to justify why we’d like large monitors for example.

Who creates those kinds of obstacles? How they *know* what size monitor I’ll need?

Continue reading

Posted in General | Leave a comment

ODP.Net Part 3

Ok, not really part three but a quick post about how the last two posts arrived at the blog in the wrong order. I can’t be bothered swapping them round so just read from the top down 😉

Posted in General | Leave a comment

Damn you ODP.NET!

This stuff really does tire me out. I’ve spent yet another day battling with Oracle’s data provider instead of doing anything meaningful. I’m calling a stored procedure with an out parameter of a varchar2. I assign an OracleParameter in exactly the same way as the stored procedures , same order and same sizes. everything matches, and I keep getting a ORA-06502 saying that there’s a size mis-match. What gives. I’ve never had this much trouble with SQL server, everything just seems to *work*. Pick up oracle and you seem to spend days battling with crap SDKs, connection problems, and weird things like TNS names junk – after all it would just be TOO complicated to specify this as an IP address in the connection string. <sigh>

Oracle isn’t my Friend.

Posted in General | Leave a comment

Damn you ODP.Net Part 2!

Ok, after spending another 1/2 day battling with the oracle tools for devstudio, i took the plunge and reflected the whole Oracle Data access component. I’m not sure I should be publicly admitting to reverse engineering Larry’s baby but if its the only way I can find out what broken, so be it. They should learn to write working code.

So I dig out reflector and run the ODP.Net assemblies through one of the reflector add-ins that brings it back to something more readable.

On inspection it seems that they’re mixing the domain values for db nulls. the OracleString performs a conversion when the column is null and actual returns the string “null”! Poor? Well I think so.

So, the next step is to look through the designer code that the ODT spits out when you drag a stored procedure onto a data set design surface. It appears to work ok, until you try using any procedure that involves varcar2 out parameters. Then it chokes. Nice.

The problem is it looks like their generated null checks aren’t working correctly. They’re testing the returned objects against NULL, and then if the object isn’t null they’re comparing the objects Value with System:DBNull. This obviously wont work since an they always return an Oracle type and the value throws an exception if the Oracle type is null. Not only that, but their implicit casting in the generated code is broken too, although that seems to be a symptom of their checks for null failing and going on the read the Value in order to cast it to a real .Net type.

The fixes are pretty simple, but it does involve editing the Table Adapters designer .CS file and fixing their ropey code.

I encountered these problems a couple of years ago, and swore never to trust them again, but heh, this is 3 years later, surely they’ve fixed the casting bugs?

Apparently not.

So, if you have the choice stick with SQLServer. For all MS’s flaws they seem to emit bug free code, and they do fix stuff.

<rant over/>

Posted in General | Leave a comment

4 Days in and its all peachy.

Apart from not understanding how to catch trains properly for the first 2days, everything’s going pretty well. The team is switched on, and the work is interesting so its all good 🙂

What I do find a bit puzzling is that other than Sheffield station there’s no way to find out which trains stop at your station, or what time it will arrive. Where there’s more than one train stopping at your destination you have no way of knowing which one will be quicker other than to ask. Even Sheffield’s fancy display board doesn’t show you the arrival times, but it does, however, show you which stations the trains will stop at.

So for instance, although there are trains that go direct from Sheffield to Leeds these can take up to an hour and 40 minutes. However, the cross country trains that start at Plymouth and end in Edinburgh also stop at both Sheffield and Leeds and yet only take 50 minutes. The trouble is you have no way of finding that out other than asking, or being a regular and already knowing!

It all seems a bit odd to me. Anyway, its no longer taking me 3.5 hours to commute! Yay!

As for the work, it does seem there’s more ASP.NET that I expected, but the data that’s driving the site is pretty interesting to work with, and because we’ve got a pretty switched on Oracle developer it’s making my life really easy! He has complete control over the organisation of the data, and if we need something that he hasn’t thought of it’s a simple task to ask him to add it, no politics involved which is a great relief.

T-Mobile Internet

For the T-Mobile internet dongle, apart from the  slightly patchy connections whilst on the train I’ve actually used less than 80mb, which is pretty good really. I was thinking that I’d be going over my tariff limit but on reflection i doubt I’ll even come close.

That 80mb consists of email, some web research and a bit of online development  i.e. uploading files to a couple of my sites. I have noticed that as soon as the connection is made, the tmobile connection manager’s transfer count starts climbing and reaches 160K of transfers, without me actually doing anything. my daughter has borrowed it too, so I was expecting the whole allowance to be used 😉 but she only ended up using 28mb for a whole night of the usual facebook/bebo/tagged rubbish !

So, Good news I dont think I’ll end up going over the limit at all!

 

Reblog this post [with Zemanta]
Posted in General | 2 Comments

It’s All GO!

Bradford's Christmas lights

Image by Neil T via Flickr

Ok, so after after a short break over Christmas, I though I’d better pull my socks up and start looking for a new contract. As everyone returned to work on the 5th of Jan, I wasn’t expecting anywhere near the response I got after posting my CV online! Either my C.V. is absolutely amazing or the IT market is ridiculously understaffed! I’d like to think it was the former, but I suspect it’s the latter! Just over 3 days into the first week and I was getting over 25 calls a day. by Thursday I’m signed up for a 6 month contract in Bradford!

Since trying to get to Bradford by car would be a real PITA , I’ve opted for a more comfortable commute and gone by train. So not only can I get a good hour and half of work done I can actually blog more often too 🙂 Finally might get a chance to write as many articles as I keep promising!

I did buy a nice little T-Mobile internet dongle too, so I can be connected whilst travelling – T-Mobile seemed like to best deal because of their usage policy. If you happen to go over their limits, there’s no real penalty. Unlike all the other operators which charge over £1 a megabyte! £1 a megabyte! That’s totally ridiculous! If I accidentally went over my limit and watched a day of youtube videos (well ok, you’d have to be pretty brain dead to watch *anything* on youtube) I could end up with a bill of over £1000! . Anyway. after a few days of email / blogging and googling, I’ll post an update on how long my usage cap is likely to last!

Reblog this post [with Zemanta]
Posted in General | Leave a comment