Query results to file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick

    Query results to file

    VB.Net 2005

    I have a Firebird DB query that returns an XML file in its rows.

    I want to execute this query and write the results (rows) to a file.

    I am using DataTables and TableAdapters.

    How can I get from the TableAdapter.Ge tBy method (via a stream?) and write
    the results to a file?

    Any suggestions?

    Rick


  • Cor Ligthert [MVP]

    #2
    Re: Query results to file

    Rick,

    The shortest answer possible.

    YourDataSet.Wri teXML("your path" , 4 different options)

    Cor

    "Rick" <Rick@LakeValle ySeed.comschree f in bericht
    news:eg1ADwF9GH A.1012@TK2MSFTN GP05.phx.gbl...
    VB.Net 2005
    >
    I have a Firebird DB query that returns an XML file in its rows.
    >
    I want to execute this query and write the results (rows) to a file.
    >
    I am using DataTables and TableAdapters.
    >
    How can I get from the TableAdapter.Ge tBy method (via a stream?) and write
    the results to a file?
    >
    Any suggestions?
    >
    Rick
    >

    Comment

    • Rick

      #3
      Re: Query results to file

      Thanks Cor,

      Thats not quite what I want.

      I ALREADY have XML which is output from the stored procedure in a column.

      I just want to save the column text to a file.

      So I guess I need some kind of stream object from this column that contains
      the text and then write that to a file.

      Pseudo code: ?.Write(MyColum n.ToString, "c:\temp|MyFile .txt")

      Anyone?

      Rick


      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
      news:OcwovVG9GH A.4568@TK2MSFTN GP02.phx.gbl...
      Rick,
      >
      The shortest answer possible.
      >
      YourDataSet.Wri teXML("your path" , 4 different options)
      >
      Cor
      >
      "Rick" <Rick@LakeValle ySeed.comschree f in bericht
      news:eg1ADwF9GH A.1012@TK2MSFTN GP05.phx.gbl...
      >VB.Net 2005
      >>
      >I have a Firebird DB query that returns an XML file in its rows.
      >>
      >I want to execute this query and write the results (rows) to a file.
      >>
      >I am using DataTables and TableAdapters.
      >>
      >How can I get from the TableAdapter.Ge tBy method (via a stream?) and
      >write the results to a file?
      >>
      >Any suggestions?
      >>
      >Rick
      >>
      >
      >

      Comment

      • Ryan S. Thiele

        #4
        Re: Query results to file

        Use the stream writer.

        --------------------------------------
        Dim Mydataset As DataSet

        Dim SW As New StreamWriter(Fi le.Open("Path", FileMode.OpenOr Create))

        'Maybe a datarow enumeration?
        Dim DR As DataRow
        For Each DR In Mydataset.Table s(0).Rows
        SW.WriteLine("N ame:" & DR(0))
        Next

        SW.Close()

        ------------------------------------------------------------

        --
        Thiele Enterprises - The Power Is In Your Hands Now!

        --
        "Rick" <Rick@LakeValle ySeed.comwrote in message
        news:uAX657R9GH A.4620@TK2MSFTN GP02.phx.gbl...
        Thanks Cor,

        Thats not quite what I want.

        I ALREADY have XML which is output from the stored procedure in a column.

        I just want to save the column text to a file.

        So I guess I need some kind of stream object from this column that contains
        the text and then write that to a file.

        Pseudo code: ?.Write(MyColum n.ToString, "c:\temp|MyFile .txt")

        Anyone?

        Rick


        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
        news:OcwovVG9GH A.4568@TK2MSFTN GP02.phx.gbl...
        Rick,
        >
        The shortest answer possible.
        >
        YourDataSet.Wri teXML("your path" , 4 different options)
        >
        Cor
        >
        "Rick" <Rick@LakeValle ySeed.comschree f in bericht
        news:eg1ADwF9GH A.1012@TK2MSFTN GP05.phx.gbl...
        >VB.Net 2005
        >>
        >I have a Firebird DB query that returns an XML file in its rows.
        >>
        >I want to execute this query and write the results (rows) to a file.
        >>
        >I am using DataTables and TableAdapters.
        >>
        >How can I get from the TableAdapter.Ge tBy method (via a stream?) and
        >write the results to a file?
        >>
        >Any suggestions?
        >>
        >Rick
        >>
        >
        >


        Comment

        • Rick

          #5
          Re: Query results to file

          Thanks Ryan,

          I'm already doing it that way - iterating through the data rows. I just
          thought there was some single step way of doing this.

          Its not really a big issue with the current program but I have a lot of xml
          and xsl returned by my database so I was looking for the easiest method to
          do this since it is something I frequently encounter.

          Rick

          "Ryan S. Thiele" <maligui@verizo n.netwrote in message
          news:7fw_g.1165 $Wp3.428@trndny 05...
          Use the stream writer.
          >
          --------------------------------------
          Dim Mydataset As DataSet
          >
          Dim SW As New StreamWriter(Fi le.Open("Path", FileMode.OpenOr Create))
          >
          'Maybe a datarow enumeration?
          Dim DR As DataRow
          For Each DR In Mydataset.Table s(0).Rows
          SW.WriteLine("N ame:" & DR(0))
          Next
          >
          SW.Close()
          >
          ------------------------------------------------------------
          >
          --
          Thiele Enterprises - The Power Is In Your Hands Now!
          >
          --
          "Rick" <Rick@LakeValle ySeed.comwrote in message
          news:uAX657R9GH A.4620@TK2MSFTN GP02.phx.gbl...
          Thanks Cor,
          >
          Thats not quite what I want.
          >
          I ALREADY have XML which is output from the stored procedure in a column.
          >
          I just want to save the column text to a file.
          >
          So I guess I need some kind of stream object from this column that
          contains
          the text and then write that to a file.
          >
          Pseudo code: ?.Write(MyColum n.ToString, "c:\temp|MyFile .txt")
          >
          Anyone?
          >
          Rick
          >
          >
          "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
          news:OcwovVG9GH A.4568@TK2MSFTN GP02.phx.gbl...
          >Rick,
          >>
          >The shortest answer possible.
          >>
          >YourDataSet.Wr iteXML("your path" , 4 different options)
          >>
          >Cor
          >>
          >"Rick" <Rick@LakeValle ySeed.comschree f in bericht
          >news:eg1ADwF9G HA.1012@TK2MSFT NGP05.phx.gbl.. .
          >>VB.Net 2005
          >>>
          >>I have a Firebird DB query that returns an XML file in its rows.
          >>>
          >>I want to execute this query and write the results (rows) to a file.
          >>>
          >>I am using DataTables and TableAdapters.
          >>>
          >>How can I get from the TableAdapter.Ge tBy method (via a stream?) and
          >>write the results to a file?
          >>>
          >>Any suggestions?
          >>>
          >>Rick
          >>>
          >>
          >>
          >
          >
          >

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Query results to file

            Rick,

            Why than not write it simple with the stramwriter as textfile.

            sr.Write.

            Cor

            "Rick" <Rick@LakeValle ySeed.comschree f in bericht
            news:OIHjL%23d9 GHA.3396@TK2MSF TNGP04.phx.gbl. ..
            Thanks Ryan,
            >
            I'm already doing it that way - iterating through the data rows. I just
            thought there was some single step way of doing this.
            >
            Its not really a big issue with the current program but I have a lot of
            xml and xsl returned by my database so I was looking for the easiest
            method to do this since it is something I frequently encounter.
            >
            Rick
            >
            "Ryan S. Thiele" <maligui@verizo n.netwrote in message
            news:7fw_g.1165 $Wp3.428@trndny 05...
            >Use the stream writer.
            >>
            >--------------------------------------
            > Dim Mydataset As DataSet
            >>
            > Dim SW As New StreamWriter(Fi le.Open("Path", FileMode.OpenOr Create))
            >>
            > 'Maybe a datarow enumeration?
            > Dim DR As DataRow
            > For Each DR In Mydataset.Table s(0).Rows
            > SW.WriteLine("N ame:" & DR(0))
            > Next
            >>
            > SW.Close()
            >>
            >------------------------------------------------------------
            >>
            >--
            >Thiele Enterprises - The Power Is In Your Hands Now!
            >>
            >--
            >"Rick" <Rick@LakeValle ySeed.comwrote in message
            >news:uAX657R9G HA.4620@TK2MSFT NGP02.phx.gbl.. .
            >Thanks Cor,
            >>
            >Thats not quite what I want.
            >>
            >I ALREADY have XML which is output from the stored procedure in a column.
            >>
            >I just want to save the column text to a file.
            >>
            >So I guess I need some kind of stream object from this column that
            >contains
            >the text and then write that to a file.
            >>
            >Pseudo code: ?.Write(MyColum n.ToString, "c:\temp|MyFile .txt")
            >>
            >Anyone?
            >>
            >Rick
            >>
            >>
            >"Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
            >news:OcwovVG9G HA.4568@TK2MSFT NGP02.phx.gbl.. .
            >>Rick,
            >>>
            >>The shortest answer possible.
            >>>
            >>YourDataSet.W riteXML("your path" , 4 different options)
            >>>
            >>Cor
            >>>
            >>"Rick" <Rick@LakeValle ySeed.comschree f in bericht
            >>news:eg1ADwF9 GHA.1012@TK2MSF TNGP05.phx.gbl. ..
            >>>VB.Net 2005
            >>>>
            >>>I have a Firebird DB query that returns an XML file in its rows.
            >>>>
            >>>I want to execute this query and write the results (rows) to a file.
            >>>>
            >>>I am using DataTables and TableAdapters.
            >>>>
            >>>How can I get from the TableAdapter.Ge tBy method (via a stream?) and
            >>>write the results to a file?
            >>>>
            >>>Any suggestions?
            >>>>
            >>>Rick
            >>>>
            >>>
            >>>
            >>
            >>
            >>
            >
            >

            Comment

            • Rick

              #7
              Re: Query results to file

              I'm new to both VB and Net, so I don't understand your comment.

              Here is what I have now:
              _______________ _______________ ____
              Dim SalesDoc As New RGardenDataSetT ableAdapters.P_ XML_SALESDOCTab leAdapter

              SalesDoc.Connec tion = FBCon

              SalesDoc.ClearB eforeFill = True

              SalesDoc.Fill(R GardenDataSet.P _XML_SALESDOC, Invoicenum,
              Application.Sta rtupPath, 5)

              SalesDoc.Fill(N ew RGardenDataSet. P_XML_SALESDOCD ataTable, Invoicenum,
              Application.Sta rtupPath, 5)

              Dim sw As StreamWriter = New StreamWriter(Pa th.Combine(XMLP ath,
              Invoicenum.ToSt ring & ".xml"))

              For Each dr As DataRow In RGardenDataSet. P_XML_SALESDOC. Rows

              sw.WriteLine(dr ("XML"))

              Next

              _______________ ______________

              So my question is: Can this be abbreviated so there is less code.

              Perhaps I can use the "Fill" method to write directly to a file stream
              rather than the DataTable (like SalesDoc.Fill(? SomeFileStream? , Invoicenum,
              Application.Sta rtupPath, 5))?

              Perhaps there is some way to get all the rows of my dr("XML") column as a
              collection and write them all at once without the iteration?

              Or, is what I am doing the best method?

              Rick


              "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
              news:uBPI7gl9GH A.3960@TK2MSFTN GP05.phx.gbl...
              Rick,
              >
              Why than not write it simple with the stramwriter as textfile.
              >
              sr.Write.
              >
              Cor
              >

              Comment

              • Cor Ligthert [MVP]

                #8
                Re: Query results to file

                Rick,

                Have a look at my first reply

                Salesdoc.WriteX ML("Your path as a string")

                In this case a datatable is as well written as a dataset.

                Cor

                "Rick" <Rick@LakeValle ySeed.comschree f in bericht
                news:utfOJRp9GH A.3760@TK2MSFTN GP02.phx.gbl...
                I'm new to both VB and Net, so I don't understand your comment.
                >
                Here is what I have now:
                _______________ _______________ ____
                Dim SalesDoc As New RGardenDataSetT ableAdapters.P_ XML_SALESDOCTab leAdapter
                >
                SalesDoc.Connec tion = FBCon
                >
                SalesDoc.ClearB eforeFill = True
                >
                SalesDoc.Fill(R GardenDataSet.P _XML_SALESDOC, Invoicenum,
                Application.Sta rtupPath, 5)
                >
                SalesDoc.Fill(N ew RGardenDataSet. P_XML_SALESDOCD ataTable, Invoicenum,
                Application.Sta rtupPath, 5)
                >
                Dim sw As StreamWriter = New StreamWriter(Pa th.Combine(XMLP ath,
                Invoicenum.ToSt ring & ".xml"))
                >
                For Each dr As DataRow In RGardenDataSet. P_XML_SALESDOC. Rows
                >
                sw.WriteLine(dr ("XML"))
                >
                Next
                >
                _______________ ______________
                >
                So my question is: Can this be abbreviated so there is less code.
                >
                Perhaps I can use the "Fill" method to write directly to a file stream
                rather than the DataTable (like SalesDoc.Fill(? SomeFileStream? ,
                Invoicenum, Application.Sta rtupPath, 5))?
                >
                Perhaps there is some way to get all the rows of my dr("XML") column as a
                collection and write them all at once without the iteration?
                >
                Or, is what I am doing the best method?
                >
                Rick
                >
                >
                "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                news:uBPI7gl9GH A.3960@TK2MSFTN GP05.phx.gbl...
                >Rick,
                >>
                >Why than not write it simple with the stramwriter as textfile.
                >>
                >sr.Write.
                >>
                >Cor
                >>
                >
                >

                Comment

                • Rick

                  #9
                  Re: Query results to file

                  I tried that, but it does not give results that I want.

                  Here is the output from my "XML" column of the SP

                  row 1 <?xml version="1.0?>
                  row 2 <salesdoc>
                  row 3 <items>
                  row 4 <item number="1234" qty="6"...>
                  ....and so on
                  row x </salesdoc>

                  When I SalesDoc.WriteX ML I got (unescaped)

                  <tag created by .Net>
                  <?xml version="1.0">
                  </tag created by .Net>
                  <tag created by .Net>
                  <salesdoc>
                  </tag created by .Net>

                  so my xml is wrapped inside NET created tags which is not what I want. I
                  think it was a mistake to mention that my sp output XML since it just
                  confused matters.

                  Forget that I am starting with XML and just consider that I want to output a
                  string column to a file stream. For this case is iterating through the rows
                  and WriteLine("text value") the best way to go?

                  Rick


                  "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                  news:%23y4TZMs9 GHA.4376@TK2MSF TNGP03.phx.gbl. ..
                  Rick,
                  >
                  Have a look at my first reply
                  >
                  Salesdoc.WriteX ML("Your path as a string")
                  >
                  In this case a datatable is as well written as a dataset.
                  >
                  Cor
                  >
                  "Rick" <Rick@LakeValle ySeed.comschree f in bericht
                  news:utfOJRp9GH A.3760@TK2MSFTN GP02.phx.gbl...
                  >I'm new to both VB and Net, so I don't understand your comment.
                  >>
                  >Here is what I have now:
                  >______________ _______________ _____
                  >Dim SalesDoc As New
                  >RGardenDataSet TableAdapters.P _XML_SALESDOCTa bleAdapter
                  >>
                  >SalesDoc.Conne ction = FBCon
                  >>
                  >SalesDoc.Clear BeforeFill = True
                  >>
                  >SalesDoc.Fill( RGardenDataSet. P_XML_SALESDOC, Invoicenum,
                  >Application.St artupPath, 5)
                  >>
                  >SalesDoc.Fill( New RGardenDataSet. P_XML_SALESDOCD ataTable, Invoicenum,
                  >Application.St artupPath, 5)
                  >>
                  >Dim sw As StreamWriter = New StreamWriter(Pa th.Combine(XMLP ath,
                  >Invoicenum.ToS tring & ".xml"))
                  >>
                  >For Each dr As DataRow In RGardenDataSet. P_XML_SALESDOC. Rows
                  >>
                  >sw.WriteLine(d r("XML"))
                  >>
                  >Next
                  >>
                  >______________ _______________
                  >>
                  >So my question is: Can this be abbreviated so there is less code.
                  >>
                  >Perhaps I can use the "Fill" method to write directly to a file stream
                  >rather than the DataTable (like SalesDoc.Fill(? SomeFileStream? ,
                  >Invoicenum, Application.Sta rtupPath, 5))?
                  >>
                  >Perhaps there is some way to get all the rows of my dr("XML") column as a
                  >collection and write them all at once without the iteration?
                  >>
                  >Or, is what I am doing the best method?
                  >>
                  >Rick
                  >>
                  >>
                  >"Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                  >news:uBPI7gl9G HA.3960@TK2MSFT NGP05.phx.gbl.. .
                  >>Rick,
                  >>>
                  >>Why than not write it simple with the stramwriter as textfile.
                  >>>
                  >>sr.Write.
                  >>>
                  >>Cor
                  >>>
                  >>
                  >>
                  >
                  >

                  Comment

                  • Cor Ligthert [MVP]

                    #10
                    Re: Query results to file

                    No just my other answer, because your XML set is a string you just can write
                    it completely in one time.

                    Cor

                    "Rick" <Rick@LakeValle ySeed.comschree f in bericht
                    news:eKJIOUu9GH A.3620@TK2MSFTN GP04.phx.gbl...
                    >I tried that, but it does not give results that I want.
                    >
                    Here is the output from my "XML" column of the SP
                    >
                    row 1 <?xml version="1.0?>
                    row 2 <salesdoc>
                    row 3 <items>
                    row 4 <item number="1234" qty="6"...>
                    ...and so on
                    row x </salesdoc>
                    >
                    When I SalesDoc.WriteX ML I got (unescaped)
                    >
                    <tag created by .Net>
                    <?xml version="1.0">
                    </tag created by .Net>
                    <tag created by .Net>
                    <salesdoc>
                    </tag created by .Net>
                    >
                    so my xml is wrapped inside NET created tags which is not what I want. I
                    think it was a mistake to mention that my sp output XML since it just
                    confused matters.
                    >
                    Forget that I am starting with XML and just consider that I want to output
                    a string column to a file stream. For this case is iterating through the
                    rows and WriteLine("text value") the best way to go?
                    >
                    Rick
                    >
                    >
                    "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                    news:%23y4TZMs9 GHA.4376@TK2MSF TNGP03.phx.gbl. ..
                    >Rick,
                    >>
                    >Have a look at my first reply
                    >>
                    >Salesdoc.Write XML("Your path as a string")
                    >>
                    >In this case a datatable is as well written as a dataset.
                    >>
                    >Cor
                    >>
                    >"Rick" <Rick@LakeValle ySeed.comschree f in bericht
                    >news:utfOJRp9G HA.3760@TK2MSFT NGP02.phx.gbl.. .
                    >>I'm new to both VB and Net, so I don't understand your comment.
                    >>>
                    >>Here is what I have now:
                    >>_____________ _______________ ______
                    >>Dim SalesDoc As New
                    >>RGardenDataSe tTableAdapters. P_XML_SALESDOCT ableAdapter
                    >>>
                    >>SalesDoc.Conn ection = FBCon
                    >>>
                    >>SalesDoc.Clea rBeforeFill = True
                    >>>
                    >>SalesDoc.Fill (RGardenDataSet .P_XML_SALESDOC , Invoicenum,
                    >>Application.S tartupPath, 5)
                    >>>
                    >>SalesDoc.Fill (New RGardenDataSet. P_XML_SALESDOCD ataTable, Invoicenum,
                    >>Application.S tartupPath, 5)
                    >>>
                    >>Dim sw As StreamWriter = New StreamWriter(Pa th.Combine(XMLP ath,
                    >>Invoicenum.To String & ".xml"))
                    >>>
                    >>For Each dr As DataRow In RGardenDataSet. P_XML_SALESDOC. Rows
                    >>>
                    >>sw.WriteLine( dr("XML"))
                    >>>
                    >>Next
                    >>>
                    >>_____________ _______________ _
                    >>>
                    >>So my question is: Can this be abbreviated so there is less code.
                    >>>
                    >>Perhaps I can use the "Fill" method to write directly to a file stream
                    >>rather than the DataTable (like SalesDoc.Fill(? SomeFileStream? ,
                    >>Invoicenum, Application.Sta rtupPath, 5))?
                    >>>
                    >>Perhaps there is some way to get all the rows of my dr("XML") column as
                    >>a collection and write them all at once without the iteration?
                    >>>
                    >>Or, is what I am doing the best method?
                    >>>
                    >>Rick
                    >>>
                    >>>
                    >>"Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                    >>news:uBPI7gl9 GHA.3960@TK2MSF TNGP05.phx.gbl. ..
                    >>>Rick,
                    >>>>
                    >>>Why than not write it simple with the stramwriter as textfile.
                    >>>>
                    >>>sr.Write.
                    >>>>
                    >>>Cor
                    >>>>
                    >>>
                    >>>
                    >>
                    >>
                    >
                    >

                    Comment

                    Working...