Friday, October 04, 2013

OMG why was this so difficult...

So, today my challenge was sorting on a gridview inside an ajax update panel...  Note to self: no more sorting/paging in update panels (requires javascript, which I have about as much interest in as cutting a finger off).  I figured instead of trying to figure java out today I opted to remove the sorting from the gridview itself and OUTSIDE the update panel put two drop down lists, one for the column name to sort and the other for ASC or DESC.  With enjoying VB so much I figured I'd get all fancy with a couple subs to call instead of writing the same code over and over in the code behind, did I mention I'm using SqlDataSources...

So, the trick was first to try to parameterize the order by clause of the data source.  This did not got over well...
 
Ok, so whatever instead of wasting time with this I figured I'd just change the data sources select command on the fly as required, something like:
 
Dim strSC As String = SqlDataSource1.SelectCommand
Dim ordbycol As String = DropDownList1.SelectedValue
Dim ordbysort As String = DropDownList2.SelectedValue
Dim ordby As String = " ORDER BY " & ordbycol & " " & ordbysort
SqlDataSource1.SelectCommand = strSC & ordby
 
And voila order by done... But wait... nope, a sql exception around the order by.  So, next I catch the exception and drop a response.write(strSC & ordby), copy and paste into Management Studio, declare and set the parameters and surprise, surprise the query runs fine, no errors, wtf...
 
So what was the problem, how about you tell me, cause I still don't know.  What I do know though is that where required if I added:
 
SqlDataSource1.SelectCommand = SqlDataSource1.SelectCommand & " ORDER BY " & DropDownList1.SelectedValue & " " & DropDownList2.SelectedValue & ""
 
before setting the parameters all was well with the world.  I'm going to go with the fact that the double quote I dropped and the end (that I didn't in my initial sub) was what did it.  But, I've wasted enough on my life today to figure out why it didn't work, but if any actual educated people out there stumble upon this and care to share, your comments will be greatly appreciated.
 
-T

This is the first...

I've decided to start a blog to capture what an uneducated, wannabe developer of all things IT learns from the powers of trial and error and Google.  I've worked for a decade in this position and aside from my lacking of any certification, bachelor degrees and hell, even a high school diploma my employer seems to have faith in my abilities.

I work for a distribution warehousing company.  I started at the very bottom and throughout the years worked my way through quite a few positions eventually nesting in my "Application Specialist" role.  My real strength that got me here was my strong interest in the warehouse management system we use and my ability to read documentation to figure stuff out.  Sounds pretty simple, however the documentation was roughly translated from several different languages so trying to understand it was something else and that's where the trial and error came in to play.

I enjoy SQL, PL/SQL, SQL Server, M$ Office, Visual Studio, Oracle, SharePoint, ASP.NET and VB.  I HATE javascript and C#.  However, I will admit that knowing those latter two are crucial and one day I'll get around to figuring them out.  I started in excel, writing complex "applications" (used very loosely) using multiple workbooks and network shares for data tracking.  Then moved into Access as VBA and Excel forms were something I lacked interest in.  The turning point for me was when one day, someone accidentally deleted one of the network shares where all my excel and access applications resided and low and behold our backups did not include this location, needless to say about three years of my developmental life were lost with a couple clicks of a mouse.  I decided at this point that SQL server and Access (ADP) were the way to go.  Later I realized (and this is solely my opinion) that Access was... limited... and with the integration of our new fandangled SharePoint server that ASP.NET was the way to go (and I love it).

Now, during all this Excel, Access, SharePoint and ASP.NET hogwash I was actively involved in writing fairly complex PL/SQL datasets and SSRS reports in Visual Studio.  I've been very fortunate that the company I work for invests in IT and I've been blessed with all the latest and greatest from Microsoft as it's releases on MSDN subscription services.  I've used every Visual Studio from 2005 and up (currently using 2012) as well as every M$ office product (all of them) from 2003 and up.  Same goes for SQL Server 2005 and up and SharePoint 3.0 and up.

I am very uneducated though, however consider myself very intelligent and have a very keen interest in these types of things.  Being a father of four half way through my third decade of life I not only cannot afford and education; I just don't have time.

So, in closing; this blog will mostly be about day to day challenges I face in the world of IT with the solutions I found.  They will not always be the right solutions per say, but are workable solutions.  They will be about PL/SQL, SSRS (now SSDT), SharePoint, ASP.NET, VB and I may throw in a personal life experience, however unlikely.  If you decide to use one of my solutions, please keep in mind the following:
first and foremost I'm running with the grade 12 education, I may get into the details (life experience) as to why I did not get a diploma in a future post
secondly, we work intRAnet.  I'm not overly concerned with SQL injection attacks or extreme validation.
Lastly, you do it at your own risk and I am in no way responsible for it blowing anything up on your end.

I hope you enjoy and wish you the very best in your endeavours (and look forward to any comments, good or bad).

-T