Home All Groups Group Topic Archive Search About

Query results to file

Author
20 Oct 2006 3:25 PM
Rick
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.GetBy method (via a stream?) and write
the results to a file?

Any suggestions?

Rick

Author
20 Oct 2006 4:34 PM
Cor Ligthert [MVP]
Rick,

The shortest answer possible.

YourDataSet.WriteXML("your path" , 4 different options)

Cor

Show quoteHide quote
"Rick" <R***@LakeValleySeed.com> schreef in bericht
news:eg1ADwF9GHA.1012@TK2MSFTNGP05.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.GetBy method (via a stream?) and write
> the results to a file?
>
> Any suggestions?
>
> Rick
>
Author
21 Oct 2006 2:41 PM
Rick
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(MyColumn.ToString, "c:\temp|MyFile.txt")

Anyone?

Rick


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:OcwovVG9GHA.4568@TK2MSFTNGP02.phx.gbl...
> Rick,
>
> The shortest answer possible.
>
> YourDataSet.WriteXML("your path" , 4 different options)
>
> Cor
>
> "Rick" <R***@LakeValleySeed.com> schreef in bericht
> news:eg1ADwF9GHA.1012@TK2MSFTNGP05.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.GetBy method (via a stream?) and
>> write the results to a file?
>>
>> Any suggestions?
>>
>> Rick
>>
>
>
Author
21 Oct 2006 9:25 PM
Ryan S. Thiele
Use the stream writer.

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

    Dim SW As New StreamWriter(File.Open("Path", FileMode.OpenOrCreate))

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

    SW.Close()

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

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

--
"Rick" <R***@LakeValleySeed.com> wrote in message
news:uAX657R9GHA.4620@TK2MSFTNGP02.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(MyColumn.ToString, "c:\temp|MyFile.txt")

Anyone?

Rick


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:OcwovVG9GHA.4568@TK2MSFTNGP02.phx.gbl...
> Rick,
>
> The shortest answer possible.
>
> YourDataSet.WriteXML("your path" , 4 different options)
>
> Cor
>
> "Rick" <R***@LakeValleySeed.com> schreef in bericht
> news:eg1ADwF9GHA.1012@TK2MSFTNGP05.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.GetBy method (via a stream?) and
>> write the results to a file?
>>
>> Any suggestions?
>>
>> Rick
>>
>
>
Author
22 Oct 2006 1:39 PM
Rick
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" <mali***@verizon.net> wrote in message
news:7fw_g.1165$Wp3.428@trndny05...
Show quoteHide quote
> Use the stream writer.
>
> --------------------------------------
>    Dim Mydataset As DataSet
>
>    Dim SW As New StreamWriter(File.Open("Path", FileMode.OpenOrCreate))
>
>    'Maybe a datarow enumeration?
>    Dim DR As DataRow
>    For Each DR In Mydataset.Tables(0).Rows
>        SW.WriteLine("Name:" & DR(0))
>    Next
>
>    SW.Close()
>
> ------------------------------------------------------------
>
> --
> Thiele Enterprises - The Power Is In Your Hands Now!
>
> --
> "Rick" <R***@LakeValleySeed.com> wrote in message
> news:uAX657R9GHA.4620@TK2MSFTNGP02.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(MyColumn.ToString, "c:\temp|MyFile.txt")
>
> Anyone?
>
> Rick
>
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:OcwovVG9GHA.4568@TK2MSFTNGP02.phx.gbl...
>> Rick,
>>
>> The shortest answer possible.
>>
>> YourDataSet.WriteXML("your path" , 4 different options)
>>
>> Cor
>>
>> "Rick" <R***@LakeValleySeed.com> schreef in bericht
>> news:eg1ADwF9GHA.1012@TK2MSFTNGP05.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.GetBy method (via a stream?) and
>>> write the results to a file?
>>>
>>> Any suggestions?
>>>
>>> Rick
>>>
>>
>>
>
>
>
Author
23 Oct 2006 4:05 AM
Cor Ligthert [MVP]
Rick,

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

sr.Write.

Cor

Show quoteHide quote
"Rick" <R***@LakeValleySeed.com> schreef in bericht
news:OIHjL%23d9GHA.3396@TK2MSFTNGP04.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" <mali***@verizon.net> wrote in message
> news:7fw_g.1165$Wp3.428@trndny05...
>> Use the stream writer.
>>
>> --------------------------------------
>>    Dim Mydataset As DataSet
>>
>>    Dim SW As New StreamWriter(File.Open("Path", FileMode.OpenOrCreate))
>>
>>    'Maybe a datarow enumeration?
>>    Dim DR As DataRow
>>    For Each DR In Mydataset.Tables(0).Rows
>>        SW.WriteLine("Name:" & DR(0))
>>    Next
>>
>>    SW.Close()
>>
>> ------------------------------------------------------------
>>
>> --
>> Thiele Enterprises - The Power Is In Your Hands Now!
>>
>> --
>> "Rick" <R***@LakeValleySeed.com> wrote in message
>> news:uAX657R9GHA.4620@TK2MSFTNGP02.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(MyColumn.ToString, "c:\temp|MyFile.txt")
>>
>> Anyone?
>>
>> Rick
>>
>>
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
>> news:OcwovVG9GHA.4568@TK2MSFTNGP02.phx.gbl...
>>> Rick,
>>>
>>> The shortest answer possible.
>>>
>>> YourDataSet.WriteXML("your path" , 4 different options)
>>>
>>> Cor
>>>
>>> "Rick" <R***@LakeValleySeed.com> schreef in bericht
>>> news:eg1ADwF9GHA.1012@TK2MSFTNGP05.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.GetBy method (via a stream?) and
>>>> write the results to a file?
>>>>
>>>> Any suggestions?
>>>>
>>>> Rick
>>>>
>>>
>>>
>>
>>
>>
>
>
Author
23 Oct 2006 11:13 AM
Rick
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 RGardenDataSetTableAdapters.P_XML_SALESDOCTableAdapter

SalesDoc.Connection = FBCon

SalesDoc.ClearBeforeFill = True

SalesDoc.Fill(RGardenDataSet.P_XML_SALESDOC, Invoicenum,
Application.StartupPath, 5)

SalesDoc.Fill(New RGardenDataSet.P_XML_SALESDOCDataTable, Invoicenum,
Application.StartupPath, 5)

Dim sw As StreamWriter = New StreamWriter(Path.Combine(XMLPath,
Invoicenum.ToString & ".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.StartupPath, 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


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uBPI7gl9GHA.3960@TK2MSFTNGP05.phx.gbl...
> Rick,
>
> Why than not write it simple with the stramwriter as textfile.
>
> sr.Write.
>
> Cor
>
Author
23 Oct 2006 4:50 PM
Cor Ligthert [MVP]
Rick,

Have a look at my first reply

Salesdoc.WriteXML("Your path as a string")

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

Cor

Show quoteHide quote
"Rick" <R***@LakeValleySeed.com> schreef in bericht
news:utfOJRp9GHA.3760@TK2MSFTNGP02.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 RGardenDataSetTableAdapters.P_XML_SALESDOCTableAdapter
>
> SalesDoc.Connection = FBCon
>
> SalesDoc.ClearBeforeFill = True
>
> SalesDoc.Fill(RGardenDataSet.P_XML_SALESDOC, Invoicenum,
> Application.StartupPath, 5)
>
> SalesDoc.Fill(New RGardenDataSet.P_XML_SALESDOCDataTable, Invoicenum,
> Application.StartupPath, 5)
>
> Dim sw As StreamWriter = New StreamWriter(Path.Combine(XMLPath,
> Invoicenum.ToString & ".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.StartupPath, 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]" <notmyfirstn***@planet.nl> wrote in message
> news:uBPI7gl9GHA.3960@TK2MSFTNGP05.phx.gbl...
>> Rick,
>>
>> Why than not write it simple with the stramwriter as textfile.
>>
>> sr.Write.
>>
>> Cor
>>
>
>
Author
23 Oct 2006 8:51 PM
Rick
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.WriteXML 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


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23y4TZMs9GHA.4376@TK2MSFTNGP03.phx.gbl...
> Rick,
>
> Have a look at my first reply
>
> Salesdoc.WriteXML("Your path as a string")
>
> In this case a datatable is as well written as a dataset.
>
> Cor
>
> "Rick" <R***@LakeValleySeed.com> schreef in bericht
> news:utfOJRp9GHA.3760@TK2MSFTNGP02.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
>> RGardenDataSetTableAdapters.P_XML_SALESDOCTableAdapter
>>
>> SalesDoc.Connection = FBCon
>>
>> SalesDoc.ClearBeforeFill = True
>>
>> SalesDoc.Fill(RGardenDataSet.P_XML_SALESDOC, Invoicenum,
>> Application.StartupPath, 5)
>>
>> SalesDoc.Fill(New RGardenDataSet.P_XML_SALESDOCDataTable, Invoicenum,
>> Application.StartupPath, 5)
>>
>> Dim sw As StreamWriter = New StreamWriter(Path.Combine(XMLPath,
>> Invoicenum.ToString & ".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.StartupPath, 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]" <notmyfirstn***@planet.nl> wrote in message
>> news:uBPI7gl9GHA.3960@TK2MSFTNGP05.phx.gbl...
>>> Rick,
>>>
>>> Why than not write it simple with the stramwriter as textfile.
>>>
>>> sr.Write.
>>>
>>> Cor
>>>
>>
>>
>
>
Author
24 Oct 2006 4:52 PM
Cor Ligthert [MVP]
No just my other answer, because your XML set is a string you just can write
it completely in one time.

Cor

Show quoteHide quote
"Rick" <R***@LakeValleySeed.com> schreef in bericht
news:eKJIOUu9GHA.3620@TK2MSFTNGP04.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.WriteXML 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]" <notmyfirstn***@planet.nl> wrote in message
> news:%23y4TZMs9GHA.4376@TK2MSFTNGP03.phx.gbl...
>> Rick,
>>
>> Have a look at my first reply
>>
>> Salesdoc.WriteXML("Your path as a string")
>>
>> In this case a datatable is as well written as a dataset.
>>
>> Cor
>>
>> "Rick" <R***@LakeValleySeed.com> schreef in bericht
>> news:utfOJRp9GHA.3760@TK2MSFTNGP02.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
>>> RGardenDataSetTableAdapters.P_XML_SALESDOCTableAdapter
>>>
>>> SalesDoc.Connection = FBCon
>>>
>>> SalesDoc.ClearBeforeFill = True
>>>
>>> SalesDoc.Fill(RGardenDataSet.P_XML_SALESDOC, Invoicenum,
>>> Application.StartupPath, 5)
>>>
>>> SalesDoc.Fill(New RGardenDataSet.P_XML_SALESDOCDataTable, Invoicenum,
>>> Application.StartupPath, 5)
>>>
>>> Dim sw As StreamWriter = New StreamWriter(Path.Combine(XMLPath,
>>> Invoicenum.ToString & ".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.StartupPath, 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]" <notmyfirstn***@planet.nl> wrote in message
>>> news:uBPI7gl9GHA.3960@TK2MSFTNGP05.phx.gbl...
>>>> Rick,
>>>>
>>>> Why than not write it simple with the stramwriter as textfile.
>>>>
>>>> sr.Write.
>>>>
>>>> Cor
>>>>
>>>
>>>
>>
>>
>
>