Query results to file

  • Thread starter Thread starter Rick
  • Start date Start date
R

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
 
Rick,

The shortest answer possible.

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

Cor
 
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
 
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!

--
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
 
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
 
Rick,

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

sr.Write.

Cor
 
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
 
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
 
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
 
No just my other answer, because your XML set is a string you just can write
it completely in one time.

Cor
 
Back
Top