Exporting Data from DataSet to text file or xls file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madankarmukta
    Contributor
    • Apr 2008
    • 308

    Exporting Data from DataSet to text file or xls file

    Hi all,

    Is there any way by which I can export the data from the dataset table to the text file or xls file ?

    Currently I implemented this by itterating through each row of the table and writting the data to file.I want to avoid iteration.It occured to me bcoz skipping iteration will improve the performance.

    Please Help..

    Thanks!
  • ssnaik84
    New Member
    • Aug 2009
    • 149

    #2
    Do you want to save .xls file on disk or just to create-n-send through browser on-the-fly?
    in second case, you just need to set page header...

    Code:
    HttpContext.Current.Response.ContentType = "text/csv";
    HttpContext.Current.Response.AddHeader("Pragma", "public");

    Comment

    • madankarmukta
      Contributor
      • Apr 2008
      • 308

      #3
      Originally posted by ssnaik84
      Do you want to save .xls file on disk or just to create-n-send through browser on-the-fly?
      in second case, you just need to set page header...

      Code:
      HttpContext.Current.Response.ContentType = "text/csv";
      HttpContext.Current.Response.AddHeader("Pragma", "public");
      Hi ,

      Thanks for your reply.

      But I want to export/copy data from dataset table to the file.The File I want to save it on local disk.

      Please provide input.

      Thanks!

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Have you looked at the .WriteXML() function?

        Comment

        • madankarmukta
          Contributor
          • Apr 2008
          • 308

          #5
          Originally posted by Plater
          Have you looked at the .WriteXML() function?
          Hi,

          Thanks for the reply.

          per my understanding .. writeXml function is used to get the xml equivalent of the table's data which is not my goal. Suppose the dataset table contains the data as -

          =============== =
          Column1 Column2
          =============== =
          Value11 Value22
          --------------------------------
          Value12 Value21
          --------------------------------
          I want it should get write to the text file as it is and not it's xml format.

          If I m wrong pls. correct me.

          Thanks again!

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Well an XML file would be able to be read by Excel.
            But for your request, you would need to format the data in a text string yourself. Looping through the data.
            You could check to see if someone has already created a function for doing that?

            Comment

            • madankarmukta
              Contributor
              • Apr 2008
              • 308

              #7
              Originally posted by Plater
              Well an XML file would be able to be read by Excel.
              But for your request, you would need to format the data in a text string yourself. Looping through the data.
              You could check to see if someone has already created a function for doing that?
              Hi,

              Thanks for the reply.

              As I stated earlier I implemented the same way as you described here.But to avoid the "looping through data" I want to have some direct way by which the data can directly exported to text file.

              Though the code was working smoothly previously, it may lead to degrade the peformance;beca use my table will now hold the records at the count of a lacs or two.

              Please provide inputs if you have any.

              Thanks again!

              Comment

              • tabla
                New Member
                • Sep 2009
                • 8

                #8
                Hi,
                Have u tried it with UTL package.check the same it is very fast.

                Tabla

                Comment

                • madankarmukta
                  Contributor
                  • Apr 2008
                  • 308

                  #9
                  Originally posted by tabla
                  Hi,
                  Have u tried it with UTL package.check the same it is very fast.

                  Tabla
                  Could you pls. elaborate more on what you want to say ..?

                  Thanks!

                  Comment

                  • tabla
                    New Member
                    • Sep 2009
                    • 8

                    #10
                    Hi,
                    There is one package UTL_FILE in oracle which read/write/append the data into existing or New .txt or .xls or .csv file.

                    First have all the data which u want to write in file into cursor.
                    Then open a file in UTL directory (take help of dba to know the path).
                    Using UTL_FLIE.PUT_LI NE procedure you can write a data in to FILE.
                    After reading all records from cursor close the open file.

                    Tabla

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      In case you're not using an Oracle Database....

                      It is probably a good idea if you research XML Serialization. The MSDN Library is a great place to start your research. For example it has an Introduction to XML Serialization article that states that you can use a XmlSerializer to serailize DataSet objects as XML.


                      Happy Coding
                      -Frinny

                      Comment

                      • madankarmukta
                        Contributor
                        • Apr 2008
                        • 308

                        #12
                        Originally posted by Frinavale
                        In case you're not using an Oracle Database....

                        It is probably a good idea if you research XML Serialization. The MSDN Library is a great place to start your research. For example it has an Introduction to XML Serialization article that states that you can use a XmlSerializer to serailize DataSet objects as XML.


                        Happy Coding
                        -Frinny
                        Hi,

                        Thanks for your reply.

                        Per my understading Xmlserializatio n won't be useful. I don't want to transfer/post the object to and fro network/machines.I just want to get the data from the table to the text file as it is.Please provide input if you have any.

                        Thanks!

                        Comment

                        • madankarmukta
                          Contributor
                          • Apr 2008
                          • 308

                          #13
                          Hi All,

                          Any inputs..?

                          Please reply!

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #14
                            Originally posted by madankarmukta
                            Hi All,

                            Any inputs..?

                            Please reply!
                            create/open file. Write contents. flush stream and close.
                            Not a complicated task?

                            Comment

                            Working...