Thinking outside the box

SteelePrice.Net

My Links

Twitter Updates


Get Microsoft Silverlight
follow me

Article Categories

Archives

Post Categories

Image Galleries

Dot Net

General

Linux

OneNote

Windows

TechED Bloggers
Visual Basic Bloggers (OPML)

July 2003 Entries

Version XXX

I, like just about all of you, need to store my code updates in some kind of version control system. Most Microsoft language based coders use VSS by default because it integrates well with Visual Studio and is pretty well hardwired into everything. Most Linux developers use CVS as their standard system. Both are, of course, incompatible with each other and were created aeons ago sometime during the Precambrian Period.

posted @ Tuesday, July 29, 2003 10:26 AM | Feedback (0)

Quagmired in Kernel Patches

I have been building a NAS box to use for a File Server for the last several days.

I had originally thought it would be rather easy to accomplish and normally it would...

However, I have some strange hardware requirements that doesn't want to co-operate, Firewire is causing some grief.

posted @ Monday, July 21, 2003 11:16 AM | Feedback (5)

CSS The way it SHOULD be
CSS Done Right
Finally there is a place to answer all those questions about how to do CSS Correctly and to incorporate it into your projects for real Theming. I know that this has been naggin at me for a really long time. How do we make CSS ubiquitous across all browsers, avoid those really "cool" bleeding edge techniques that only work in ONE browser, etc.

posted @ Wednesday, July 09, 2003 3:02 PM | Feedback (0)

Windows SB Server 2003 Lite
Didn't I just talk about this a couple of weeks ago...

posted @ Thursday, July 03, 2003 2:29 PM | Feedback (0)

Transformance Obsolescence

I don't mind things going away if what replaces them is useful and intuitive. One change made to VS.NET 2003 that greatly affected alot of my production codebase was Xsl.Transform.

I use this constantly and it irked me to see that blue squiggly and intellisense prompting me all the time to change it so I decided to look at it today.

The main thing I use Xsl.Transform to do is to take a returned XMLDocument from SQL 2000 and change it into some HTML I devised for multi-column drop down lists. I am planning a full article on how to do this, but in the meantime here is a taste of what I do.

I create an xml document from SQL by getting a resultset using FOR XML AUTO, ELEMENTS in my Stored Procedures. To actually create the XmlDocument,

I use the following function from my DataObject_MSSQL Class:

Public Overloads Shared Function getXMLDocument(ByVal ConnectionString As String, _
ByVal SQL As String, ByVal ParamArray Parameters() As SqlParameter) As XmlDocument
        '// Overloaded method for StoredProcs to just retrieve an XML String, the StoredProc must include FOR XML,
        '// so we don't have to convert it, let SQL Server do the work for you.
        '// be aware that what is returned is actually a fragment, there is no root element and no <xml> tag
        Dim cn As SqlConnection
        Dim cmd As SqlCommand
        Dim dr As SqlDataReader
        Dim sb As New StringBuilder
        Dim d As New XmlDocument
        Try
            cn = New SqlConnection(ConnectionString)
            If Not (cn Is Nothing) Then 
                cn.Open() 
            Else 
                '// sort of pointless to continue.
                Return Nothing
            End If
            cmd = New SqlCommand(SQL, cn)
            '// String Parameters passed denotes Stored Proc with params from the server
            cmd.CommandType = CommandType.StoredProcedure
            getParameters(SQL, cn, cmd, Parameters)
            '// Execute scalar won't work, it has a size limit on returned strings.
            '// Create a SQL data reader
            dr = cmd.ExecuteReader()
            '// We need a while because SQL Server will return large strings in multiple rows
            '// however there is always only one column
            While dr.Read()
                sb.Append(dr.Item(0))
            End While
            dr.Close()
            If sb.ToString(0, 1) = "<" Then
                '// verify that xml is returned, otherwise it would create an error in d.LoadXml
                '// we need to wrap what SQL Server returns with a root element
                sb.Insert(0, "")
                sb.Append("")
                '// now it will load correctly
                d.LoadXml(sb.ToString)
                Return d
            Else
                Return Nothing
            End If
        Catch exc As Exception
            ErrorHandler("DataObject_MSSQL.getXMLDocument", exc.Source, exc.Message)
            Return Nothing
        Finally
            cmd = Nothing
            cn.Dispose()
        End Try
    End Function

Armed with this Document, I can the process it into what I need with the following function in my aspx Page's Code behind:

Private Sub LoadXML(ByRef ctl As HtmlGenericControl, ByVal sql As String, ByVal XSLDocument As String, _
 ByVal ParamArray params() As SqlParameter)
        Dim xml As XmlDocument
        Dim xslt As New Xsl.XslTransform
        Dim ms As New IO.MemoryStream
        Dim xtw As New XmlTextWriter(ms, Nothing)
        Try
            xml = getXMLDocument(_cs, sql, params)
            If (xml Is Nothing) Then Exit Sub
            If XSLDocument <> "" Then
                xslt.Load(XSLDocument)
                xslt.Transform(xml.DocumentElement, Nothing, xtw, Nothing)
                ctl.InnerHtml = Encoding.Default.GetString(ms.ToArray)
            Else
                ctl.InnerHtml = xml.DocumentElement.OuterXml
            End If
        Catch exc As Exception
            AspxErrorHandler("MyPage.aspx.vb.LoadXML", exc.source, exc.message)
        Finally
        End Try
    End Sub

This function is called repeatedly in my Page_Load event to populate several drop downs, but you can use it for alot of other things too.

I use it like this:

LoadXML(MyDiv, "ap_list_orders_XML", Server.MapPath("list_orders.xslt"), _ 
New SqlParameter("@CustomerID", Request.QueryString("CustomerID")))

And viola!, with one line in my aspx page, I have created a connection to SQL Server, Loaded an XML Document, Transformed it with XSLT, stuffed it into a

so I can use it as a popup and closed the connection.

You could also use this to populate Blocks in a CMS application or to gather RSS feeds, etc.

You get the picture. Reducing it to a one-liner makes it all the more useful as a tool in your development arsenal.

P.S. One thing in the code you should notice that was driving me batty...

ctl.InnerHtml = Encoding.Default.GetString(ms.ToArray)

This takes a Byte Array (the MemoryStream) and makes it a String. I had previously been using a convoluted way of doing this but revisiting the code due to the Obsolesence of the Transform Method made me think about better ways to accomplish that task as well.

posted @ Wednesday, July 02, 2003 8:55 PM | Feedback (7)

SqlHelper?

This thing is supposed to help us make accessing the database easier? It seems like it only makes it harder to me... I chose something similar, but went a few steps further in my abstraction. I wrote my .NET data abstraction layer to just return a DataTable, an ArrayList or an XMLDocument.

Now I have a one line entry to acc

posted @ Wednesday, July 02, 2003 11:45 AM | Feedback (1)

Blogroll Me!

Blog Search Engine

Copyright © 2003-2004 H. Steele Price, IV -
All opinions are my own, not necessarily those of my employer, your mother, or any government agency.