14 replies
by n3bu1a
Hi everyone!
Thanks for taking the time out of your busy schedule to visit my corner of the web.? I'm going to use this blog as a sounding board for my thoughts on pretty much everything, so if you're interested in anything, check back often.? I'll be updating a lot and there will always be something different.
by n3bu1a
Hey everybody.? Right now I'm working on a "on-the-fly" method of converting a .Net DataSet to an ADODB.Recordset.? After doing countless searches on google (and any site therein), I found that the majority of conversion methodologies required storing the file to hard disk (which can be pretty painful if you do web development), or did just a plain lousy job of explaining anything.
Once I get the process flushed out and a little better commented, I'll post it.? Just to give some background, the conversion methods are encapsulated in its own class, so it should be fairly portable.? I'm hoping to have this up by either the end of this week, or beginning of next.? Enjoy!
by n3bu1a
Hey!
In my last post, I mentioned that I would have something set up for converting a .Net DataSet to an ADODB.Recordset.? I actually have this finished, but as I am a lazy bastard, I don't have it set up yet.
Actually, here's my blog/thought of the day.? Why do ex's make life difficult?? My ex-fiancee (never got married) is trying to make life difficult.? While we were dating/engaged, I backed her car in to a pole, and I told her I would fix it.? I have hit some extreme situations since then and have not been able to get it fixed - for those that know me, you'll know what I'm talking about, for those that don't and are curious, please drop me a line.? Anyway, I can only talk to my ex through e-mail, which is tough enough, and have managed to "misunderstand" a bunch of things.? Now she's threatening legal action after I have saved her from a lot of financial ruin.? Am I wrong for being slightly upset about this?? Why do lawyers need to be brought in?? Why can't things be easier?? Why does my ex hate me?? Oh well.? I will not let this situation beat me down.? Thanks for listening.? The conversiont thing is coming.
Later!
by n3bu1a
Ok, so I'm on this whole kick right now to better myself and create a better me.? Well, of course that includes changing my email on every frigging service I belong to, which is too many to count.? How in the hell did humanity ever live in this world without belonging to fifty different news service organizations, online stores and such?? It really makes me wonder who out there has my email address, and what could they be doing with it?? I'm sure there is a ninety year old Ukrainian women sitting in her hovel rubbing her hands together saying something along the lines like "He he he... now who can I email as Scott Allender?"? Probably would sound a lot better if you think with a ninety year old Ukranian woman accent.
by n3bu1a
Well, special thanks to friends Han Gerwitz and Ryan Stephenson.? With their direction, I found this awesome new bookmark utility calle del.icio.us.? This thing is awesome; I can pretty much upload whatever the hell I want as a bookmark and boom, it stores and puts it into html (ideal for a home page) and rss feed (great for aggregators if you want to know about my tastes and stuff).? Anyway, this thing rocks!? So much so that I've devoted an entire blog to it.
All right, I need to get out more.? I know.
by n3bu1a
All right, without further ado and sorry for the wait, here's the code for converting a DataSet to a Recordset without using a hard file, i.e. the Microsoft way.? I've got this thing embedded in a web service, but feel free to incorporate it into a standalone dll.? As my intention for this thing is to share it as much as possible (it was hell trying to figure out how to make this work without a hard file), feel free to copy and use however you want.
Public Class VbConvert
'**************************************************************************
' Method Name : GetADORS
' Description : Takes a DataSet and converts into a Recordset. The converted
' ADODB recordset is saved as an XML file. The data is saved
' to the file path passed as parameter.
' Output : The output of this method is long. Returns 1 if successfull.
' If not throws an exception.
' Input parameters:
' 1. DataSet object
' 2. Database Name
' 3. Output file - where the converted should be written.
'**************************************************************************
Public Function GetADORS(ByVal ds As DataSet) As String
Dim strRsXml As String
'Create an xmlwriter object, to write the ADO Recordset Format XML
Try
Dim sw As New MemoryStream
Dim xwriter As New XmlTextWriter(sw, System.Text.Encoding.Default)
'call this Sub to write the ADONamespaces to the XMLTextWriter
WriteADONamespaces(xwriter)
'call this Sub to write the ADO Recordset Schema
WriteSchemaElement(ds, xwriter)
Dim TransformedDatastrm As New MemoryStream
'Call this Function to transform the Dataset xml to ADO Recordset XML
TransformedDatastrm = TransformData(ds)
'Pass the Transformed ADO REcordset XML to this Sub
'to write in correct format.
HackADOXML(xwriter, TransformedDatastrm)
xwriter.BaseStream.Position = 0
Dim sr As New StreamReader(xwriter.BaseStream)
strRsXml = sr.ReadToEnd
xwriter.Flush()
xwriter.Close()
sr.Close()
Return strRsXml.ToString
Catch ex As Exception
'Returns error message to the calling function.
Err.Raise(100, ex.Source, ex.ToString)
End Try
End Function
Private Sub WriteADONamespaces(ByRef writer As XmlTextWriter)
'The following is to specify the encoding of the xml file
'writer.WriteProcessingInstruction("xml", "version='1.0' encoding='ISO-8859-1'")
'The following is the ado recordset format
'<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
' xmlns:rs='urn:schemas-microsoft-com:rowset'
' xmlns:z='#RowsetSchema'>
' </xml>
'Write the root element
writer.WriteStartElement("", "xml", "")
'Append the ADO Recordset namespaces
writer.WriteAttributeString("xmlns", "s", Nothing, "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882")
writer.WriteAttributeString("xmlns", "dt", Nothing, "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882")
writer.WriteAttributeString("xmlns", "rs", Nothing, "urn:schemas-microsoft-com:rowset")
writer.WriteAttributeString("xmlns", "z", Nothing, "#RowsetSchema")
writer.Flush()
End Sub
Private Sub WriteSchemaElement(ByVal ds As DataSet, ByRef writer As XmlTextWriter)
'ADO Recordset format for defining the schema
' <s:Schema id='RowsetSchema'>
' <s:ElementType name='row' content='eltOnly' rs:updatable='true'>
' </s:ElementType>
' </s:Schema>
'write element schema
writer.WriteStartElement("s", "Schema", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882")
writer.WriteAttributeString("id", "RowsetSchema")
'write element ElementTyoe
writer.WriteStartElement("s", "ElementType", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882")
'write the attributes for ElementType
writer.WriteAttributeString("name", "", "row")
writer.WriteAttributeString("content", "", "eltOnly")
writer.WriteAttributeString("rs", "updatable", "urn:schemas-microsoft-com:rowset", "true")
WriteSchema(ds, writer)
'write the end element for ElementType
writer.WriteFullEndElement()
'write the end element for Schema
writer.WriteFullEndElement()
writer.Flush()
End Sub
Private Sub WriteSchema(ByVal ds As DataSet, ByRef writer As XmlTextWriter)
Dim i As Int32 = 1
Dim dc As DataColumn
For Each dc In ds.Tables(0).Columns
dc.ColumnMapping = MappingType.Attribute
writer.WriteStartElement("s", "AttributeType", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882")
'write all the attributes
writer.WriteAttributeString("name", "", dc.ToString)
writer.WriteAttributeString("rs", "number", "urn:schemas-microsoft-com:rowset", i.ToString)
writer.WriteAttributeString("rs", "baseCatalog", "urn:schemas-microsoft-com:rowset", Me.DBNAME)
writer.WriteAttributeString("rs", "baseTable", "urn:schemas-microsoft-com:rowset", _
dc.Table.TableName.ToString)
writer.WriteAttributeString("rs", "keycolumn", "urn:schemas-microsoft-com:rowset", _
dc.Unique.ToString)
writer.WriteAttributeString("rs", "autoincrement", "urn:schemas-microsoft-com:rowset", _
dc.AutoIncrement.ToString)
'write child element
writer.WriteStartElement("s", "datatype", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882")
'write attributes
writer.WriteAttributeString("dt", "type", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882", _
GetDatatype(dc.DataType.ToString))
writer.WriteAttributeString("dt", "maxlength", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882", _
dc.MaxLength.ToString)
writer.WriteAttributeString("rs", "maybenull", "urn:schemas-microsoft-com:rowset", _
dc.AllowDBNull.ToString)
'write end element for datatype
writer.WriteEndElement()
'end element for AttributeType
writer.WriteEndElement()
writer.Flush()
i = i + 1
Next
dc = Nothing
End Sub
'Function to get the ADO compatible datatype
' Feel free to add as many ADO compatible data types, I needed only two.
Private Function GetDatatype(ByVal dtype As String) As String
Select Case (dtype)
Case "System.Int32"
Return "int"
Case "System.Float"
Return "float"
Case Else
Return "string"
End Select
End Function
'Transform the data set format to ADO Recordset format
'This only transforms the data
Private Function TransformData(ByVal ds As DataSet) As MemoryStream
Dim config As New System.Configuration.AppSettingsReader
Dim xslFile As String = config.GetValue("rsXsl", Type.GetType("System.String"))
Dim instream As New MemoryStream
Dim outstream As New MemoryStream
'write the xml into a memorystream
ds.WriteXml(instream, XmlWriteMode.IgnoreSchema)
instream.Position = 0
'load the xsl document
Dim xslt As New XslTransform
xslt.Load(xslFile)
'create the xmltextreader using the memory stream
Dim xmltr As New XmlTextReader(instream)
'create the xpathdoc
Dim xpathdoc As XPathDocument = New XPathDocument(xmltr)
'create XpathNavigator
Dim nav As XPathNavigator
nav = xpathdoc.CreateNavigator
'Create the XsltArgumentList.
Dim xslArg As XsltArgumentList = New XsltArgumentList
'Create a parameter that represents the current date and time.
Dim tablename As String
xslArg.AddParam("tablename", "", ds.Tables(0).TableName)
'transform the xml to a memory stream
xslt.Transform(nav, xslArg, outstream)
instream = Nothing
xslt = Nothing
xmltr = Nothing
xpathdoc = Nothing
nav = Nothing
'outstream.Position = 0
Return outstream
End Function
'**************************************************************************
' Method Name : ConvertToRs
' Description : The XSLT does not tranform with fullendelements. For example,
' <root attr=""/> intead of <root attr=""><root/>. ADO Recordset
' cannot read this. This method is used to convert the
' elements to have fullendelements.
'**************************************************************************
Private Sub HackADOXML(ByRef wrt As XmlTextWriter, ByVal ADOXmlStream As System.IO.MemoryStream)
ADOXmlStream.Position = 0
Dim rdr As New XmlTextReader(ADOXmlStream)
Dim outStream As New MemoryStream
rdr.MoveToContent()
'if the ReadState is not EndofFile, read the XmlTextReader for nodes.
Do While rdr.ReadState <> ReadState.EndOfFile
If rdr.Name = "s:Schema" Then
wrt.WriteNode(rdr, False)
wrt.Flush()
ElseIf rdr.Name = "z:row" And rdr.NodeType = XmlNodeType.Element Then
wrt.WriteStartElement("z", "row", "#RowsetSchema")
rdr.MoveToFirstAttribute()
wrt.WriteAttributes(rdr, False)
wrt.Flush()
ElseIf rdr.Name = "z:row" And rdr.NodeType = XmlNodeType.EndElement Then
'The following is the key statement that closes the z:row
'element without generating a full end element
wrt.WriteEndElement()
wrt.Flush()
ElseIf rdr.Name = "rs:data" And rdr.NodeType = XmlNodeType.Element Then
wrt.WriteStartElement("rs", "data", "urn:schemas-microsoft-com:rowset")
ElseIf rdr.Name = "rs:data" And rdr.NodeType = XmlNodeType.EndElement Then
wrt.WriteEndElement()
wrt.Flush()
End If
rdr.Read()
Loop
wrt.WriteEndElement()
wrt.Flush()
End Sub
Private Const DBNAME As String = "******"
End Class
by n3bu1a
Ok, it's about 1 am on Tuesday morning, and I'm sitting here after working 11 hours and cleaning my house for about 5 hours.? When did life get so mundane?? I mean seriously, I'm 24, and I spent a night cleaning my house.? Granted, I could use a mundane night, so I shouldn't really be complaining, but still... I remember thinking to myself that when I was grown up things would be so much easier and exciting than as a little kid.? Now, I would love the opportunity to spend a single afternoon being childlike.? I guess that's the cosmic joke, huh?? You always want to be in a state of mind than what you're currently in.? Kind of a take on the grass is always greener thing.
Anyway, today should be much more interesting.? I start working with a new client, which is always exciting, I get to interview my first candidate for a roommate, and... I don't know.? I guess something will come up, and if it doesn't, great.? I can take the time to relax.
Oh by the way, this past weekend was great.? I finished my second bike century, a hundred mile bike ride.? This ride was sponsored by the American Diabetes Association, and if you want to donate go to the American Diabetes Association Donation page.? Diabetes is a serious, treatable illness.
by n3bu1a
Ok, so I really like this girl.? She's extremely attractive, but there are several things impeding a potential relationship between her and myself.? To elaborate, she's drop dead gorgeous, but something that has been bothering me is that the more I find out about her, the more she reminds me of my ex-fiance.? it's kind fo tough to reconcile that.? I just can't seem to get past the things that I know about this new woman, because they are so close to what I have already experienced.??
Should a learning experince (my time with my ex-fiance) cripple potential experiences with other women?
by dc guy
Most of us tend to be attracted to the same kind of person over and over again. Those are the peole we like. Those are the people who like us. We have fun together. Our values are compatible. Emotionally, instinctively, intellectually, we have preferences in people just as we have them in food and art. And they feel the same way about us.
Duh!
You should turn this dilemma into an asset. How did you enjoy the relationship with your fiancee? (Two E's please, we live in a new era and you don't want to make a gender typo!) What was the cause of the failure? Did you have good times or did you fight a lot? Was it a blind date or an accident of hormones that turned into a train wreck? Or was it a good match that just turned bad because of fate and perhaps a bit of inexperience and immaturity?
If this woman doesn't turn out to be the one you keep for life, you'll probably notice that many or most of her successors also bear a lot of resemblance to one another.
If this similarity is so spooky that it just creeps you out, then go with your gut and bail. Or if you're doggedly looking for the adventure that comes with diversity and more of the same feels like a big disappointment, then keep looking. But if you're just wondering, I'd say stop wondering and go for it. This type of woman seems to be your type. Enjoy!
by n3bu1a
So yeah, I just got back from Chicago where my youngest nephew, Austin Michael Bates, was christened.? I have such love for my sister's family; almost like it was my o own.? Anyway, anytime I go to Chicago I always return refreshed and ready for anything.? Which is good as I have my family's reunion this upcoming week, more fun with my new client, a roommate to prepare for, and as always, the other comings and goings in my life.? On the plus side, I feel pretty confident that my life will keep me very busy this week.
by n3bu1a
Well, I'm just sitting on my couch, watching my roommate play a game.? It's just a lazy day as I went out last night, drank way too much, and expecting to do it again tomorrow.
I think I'm going to try and get some more cool work stuf going on in the near future.
by n3bu1a
Ok, so I've been working on this project and for a supposed advanced .Net developer, I feel really stupid.? The basis for this project? I've been working on is to create a single application that can be extended to multiple site.? The app is database driven, so obviously the simplest, but least cost effective and maintenance nightmare, is to just create a new database everytime the app is integrated somewhere else.? What I'm doing is creating a single app that will essentially know what site it is on (so it can be skinned appropriately), and then log into a central sql server.
The part that makes me feel stupid is that I've just now figured out how wonderful and time saving overloading the page object in .Net is.? Overloading in this particular instance allows me to put the skinning code for the application in one place!? It's so incredibly wonderful, and I feel so incredibly silly for not doing this before.
Also, it's come to my attention that the Converting a dataset to a recordset code gave some errors.? I will correct that later this week.? Sorry for the trouble.? I'll also put up an example of the code I'm working with that overloads the page object so an example exists for everyone to use.
by n3bu1a
It's come to my attention that a friend of mine feels slighted for my having mentioned some work stuff before I made any mention of her.? Well ok, Sara, here is a blog dedicated to you.
Sara is a great woman who lives in San Antonio, TX.? Go Spurs!? Anyway, she and I have been friends for a few years (we even dated for a little bit, how she put up with me and my crazy antics I'll never know).? Anyway, she was just up here a while ago and we hung together (for the first time in almost two years) and it was a blast.? I look forward to the next time that she comes up.? I don't know, maybe I might make it to TX sometime in the future.
Anyway, if you'd like to learn more about Sara, feel free to read about her misadventures.
by n3bu1a
Ok, the next post I do will surely have some tech stuff in it.
When does a person realize that life is more than the stuff he/she does?? What effect does it have on a person?
Yesterday, I finished something that completely defines who I am.? After spending two+ weeks on something, I managed to get it public and feel completely secure.
Today, my feeling of strength has been blown away by someone with an entirely different strength.? The strength to forgive.? I am by far an imperfect person.? I am willing to give whatever I have for friends and loved ones provided I believe in them.? But someone I counted as a person who hated me (or at the very least disliked me), forgave me.? I can't possibly fathom how much strength, power and will that person has.? She has put me to shame, and I only hope that I can live up to the estimation I have been given.
This discussion is closed to new replies.
Trending After Hours posts
Sort by Trending