Click here to Skip to main content
15,895,142 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 13:00
professionalJörgen Andersson9-Jul-10 13:00 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 13:05
mvePIEBALDconsult9-Jul-10 13:05 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 15:05
mvePIEBALDconsult9-Jul-10 15:05 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 10:32
professionalJörgen Andersson9-Jul-10 10:32 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 10:45
mvePIEBALDconsult9-Jul-10 10:45 
GeneralRe: String.Format??? Pin
Jeremy Hutchinson9-Jul-10 8:54
professionalJeremy Hutchinson9-Jul-10 8:54 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 11:11
professionalJörgen Andersson9-Jul-10 11:11 
GeneralRe: String.Format??? Pin
CDP180211-Jul-10 20:43
CDP180211-Jul-10 20:43 
That is true, things get a bit problematic when you have many or a variable amount of parameters.

First, I would simply try to avoid the situation if that is possible. Perhaps it is possible to replace the list with a nested select statement. It really depends on the case at hand.

If that's not possible, I would put together the SQL command in my code. With a variable amount of parameters, I would simply use a loop to add the parameter placeholders to the SQL string and the parameters themselves to the command object. Taken to the extreme, this can become very ugly and results in absolutely unmaintainable code. In my current project here at work some genius tried to replace the complete data access layer with one single function which constructs every needed SQL statement in a few thousand (!) lines of spaghetti code. But, like with everything, there is no problem as long as it is used sparingly and with at least some thought.

Edit: Here is the beginning of that monster function, a worthy candidate for this board as well:

public static DataSet ArtikelHelpListe(int auswahl, string artnr, string artbez, string lnam, 
                                       string lnr, string lartnr, string wg, string mkenz,
                                       string ean, string gab, bool ges, bool bug, bool bau,
                                       bool eks, int stanort, string uid)
{
    // Here be dragons ( thousands of lines of totally worthless code)
    ....
}

A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.

I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

GeneralRe: String.Format??? Pin
Jason Christian22-Jul-10 9:05
Jason Christian22-Jul-10 9:05 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 5:09
mvePIEBALDconsult9-Jul-10 5:09 
GeneralRe: String.Format??? Pin
oggenok649-Jul-10 5:35
oggenok649-Jul-10 5:35 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 5:40
mvePIEBALDconsult9-Jul-10 5:40 
GeneralRe: String.Format??? Pin
Steve Wellens9-Jul-10 5:45
Steve Wellens9-Jul-10 5:45 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 5:51
mvePIEBALDconsult9-Jul-10 5:51 
GeneralRe: String.Format??? Pin
Single Step Debugger9-Jul-10 6:16
Single Step Debugger9-Jul-10 6:16 
GeneralRe: String.Format??? Pin
M@dHatter11-Jul-10 10:33
M@dHatter11-Jul-10 10:33 
GeneralRe: String.Format??? Pin
Not Active11-Jul-10 10:53
mentorNot Active11-Jul-10 10:53 
GeneralRe: String.Format??? Pin
PIEBALDconsult11-Jul-10 14:55
mvePIEBALDconsult11-Jul-10 14:55 
GeneralRe: String.Format??? Pin
Kunal Chowdhury «IN»17-Jul-10 18:45
professionalKunal Chowdhury «IN»17-Jul-10 18:45 
GeneralRe: String.Format??? Pin
Richard Deeming22-Jul-10 2:39
mveRichard Deeming22-Jul-10 2:39 
GeneralSuperman if-clause Pin
freakyit8-Jul-10 3:40
freakyit8-Jul-10 3:40 
GeneralRe: Superman if-clause Pin
Keith Barrow8-Jul-10 8:03
professionalKeith Barrow8-Jul-10 8:03 
GeneralRe: Superman if-clause Pin
Kevin Drzycimski8-Jul-10 8:51
Kevin Drzycimski8-Jul-10 8:51 
GeneralRe: Superman if-clause Pin
oggenok648-Jul-10 22:12
oggenok648-Jul-10 22:12 
GeneralRe: Superman if-clause Pin
Rob Grainger8-Jul-10 22:25
Rob Grainger8-Jul-10 22:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.