Advertisement

07.28.2008 at 09:05AM PDT, ID: 23601210 | Points: 100
[x]
Attachment Details

Getting data.row.datarow return in xml instead of objects value.

Asked by mackanenziebl in Web Services, Microsoft Visual Basic.Net, Visual Studio

Tags: , ,

I have a windows service that you can put in table, fields, values, etc. to create an sql query.  It worked until I moved it into Visual Studio 2005 and now it doesn't.  I am getting my xml back but the value of my row is 'system.data.datarow' instead of 'abc' or whatever the actual value is.  Any ideas?  I can see the value in the datatable arraylist but I can't see figure out what's different.  Here's the code...

<WebMethod()> Public Function DB_Query(ByVal Table As String, ByVal SearchCol As String, ByVal SearchVal As String, ByVal SearchAction As String, ByVal Distinct As String, ByVal Service As String, ByVal Userid As String, ByVal Password As String) As XmlDataDocument
        Dim LogWriter As New StreamWriter("c:\SIUDBLog.log")

        Dim objConnection As OracleConnection
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim dataDocErr As New XmlDataDocument
        LogWriter.WriteLine(Now() & " --- " & "Query DB")
        Try
            Dim objCommand, sql, dbread
            Dim strConnection As String
            'strConnection = ConfigurationSettings.AppSettings("ConnectionString")
            strConnection = "User ID=" & Userid & ";Password=" & Password & ";Data Source=" & Service & ";"
            objConnection = New OracleConnection(strConnection)
            objConnection.Open()

            LogWriter.WriteLine(Now() & " --- " & "Database Connection   " & strConnection)

            sql = "SELECT "
            If Distinct = "" Then
                sql = sql & "* "
            Else
                sql = sql & "DISTINCT " & Distinct & " "
            End If
            sql = sql & "FROM " & Table & " WHERE "

            Dim SearchColString, SearchValString, I
            SearchColString = HttpUtility.HtmlDecode(SearchCol)
            SearchValString = HttpUtility.HtmlDecode(SearchVal)
            Dim SplitChar
            Dim SearchColArray
            SplitChar = "|"
            If InStr(SearchColString, "|") = 0 Then
                SplitChar = ","
            End If
            SearchColArray = Split(SearchColString, SplitChar)
            Dim SearchValArray
            SplitChar = "|"
            If InStr(SearchValArray, "|") = 0 Then
                SplitChar = ","
            End If
            SearchValArray = Split(SearchValString, SplitChar)
            Dim ArrayBound
            ArrayBound = UBound(SearchColArray)

            For I = 0 To ArrayBound
                sql = sql & SearchColArray(I) & " " & SearchAction & " " & SearchValArray(I) & " "
                If I < ArrayBound Then
                    sql = sql & "AND "
                End If
            Next

            Dim block As String = sql

            LogWriter.WriteLine(Now() & " --- " & "SQL  " & sql)

            Dim cmd As OracleCommand = New OracleCommand
            cmd = New OracleCommand(block, objConnection)
            Dim objDataReader As OracleDataReader = cmd.ExecuteReader()
            Dim schemaTable As New DataTable
            schemaTable = objDataReader.GetSchemaTable()

            LogWriter.WriteLine(Now() & " --- " & "Queried Database")

            If Not (schemaTable Is DBNull.Value) Then
                Dim Z As Integer
                For Z = 0 To schemaTable.Rows.Count - 1
                    Dim dr = dt.NewRow()
                    dr = schemaTable.Rows(Z)
                    If objDataReader.GetDataTypeName(Z) = "Clob" Or objDataReader.GetDataTypeName(Z) = "Blob" Then
                        Dim clobcolumn As New DataColumn(objDataReader.GetName(Z), GetType(Byte()))
                        dt.Columns.Add(clobcolumn)
                    Else
                        Dim column As New DataColumn(objDataReader.GetName(Z))
                        dt.Columns.Add(column)
                    End If
                Next Z
                    ds.Tables.Add(dt)
            End If
            While objDataReader.Read()
                Dim dr = dt.NewRow()
                Dim Z As Integer
                For Z = 0 To objDataReader.FieldCount - 1
                    If objDataReader.GetDataTypeName(Z) = "Clob" Then
                        Dim orablob As OracleClob = objDataReader.GetOracleClob(Z)
                        Dim BlobData As Byte()
                        ReDim BlobData(orablob.Length)
                        Dim J As Integer = orablob.Read(BlobData, 0, System.Convert.ToInt32(orablob.Length))
                        'Dim FsOut As FileStream = New FileStream("c:\inetpub\wwwroot\BlobTest\BlobData.txt", FileMode.OpenOrCreate)
                        'FsOut.Read(BlobData, 0, BlobData.Length)
                        'FsOut.Close()
                        dr(Z) = BlobData
                    ElseIf objDataReader.GetDataTypeName(Z) = "Blob" Then
                        Dim orablob As OracleBlob = objDataReader.GetOracleBlob(Z)
                        Dim BlobData As Byte()
                        ReDim BlobData(orablob.Length)
                        Dim J As Integer = orablob.Read(BlobData, 0, System.Convert.ToInt32(orablob.Length))
                        'Dim FsOut As FileStream = New FileStream("c:\inetpub\wwwroot\BlobTest\BlobData.txt", FileMode.OpenOrCreate)
                        'FsOut.Read(BlobData, 0, BlobData.Length)
                        'FsOut.Close()
                        dr(Z) = BlobData
                    Else
                            dr(Z) = objDataReader.GetValue(Z)
                            'ds.Tables.Add(dt)
                    End If
                        'ds.Tables.Add(dt)
                Next Z
                    dt.Rows.Add(dr)
                    objDataReader.NextResult()
            End While

            objConnection.Close()

            LogWriter.WriteLine(Now() & " --- " & "Done")
            LogWriter.Flush()
            LogWriter.Close()
            LogWriter = Nothing

            Dim dataDoc As New XmlDataDocument(ds)
            If dataDoc.HasChildNodes = False Then
                dataDoc.LoadXml("<error>No records found</error>")
                Return dataDoc
            Else
                Return dataDoc
            End If

        Catch ex As Exception
            objConnection.Close()
            LogWriter.WriteLine(Now() & " --- " & "ERROR Message   " & ex.Message.ToString & "InnerException   " & ex.Source)
            dataDocErr.LoadXml("<error>" & ex.Message.ToString & "</error>")
            LogWriter.Flush()
            LogWriter.Close()
            LogWriter = Nothing
            Return dataDocErr
        End Try
    End FunctionStart Free Trial
[+][-]07.28.2008 at 09:06AM PDT, ID: 22104387

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.28.2008 at 10:08PM PDT, ID: 22108756

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08.03.2008 at 12:57PM PDT, ID: 22148650

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08.03.2008 at 02:05PM PDT, ID: 22148840

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628