Vb.net 2008 - System.data.enumerablerowcollection(of system.data.datarow) convert to string???

R

Rob W

Greetings,

For no shortage of trying I am unable to convert the contents of a datarow
(containing xml data) to type string, using .tostring results in conversion
errors in the linq and when adding
adding as an xml element to an xmldocument the literal words systems.data
(see code below for examples).

Is it possible from the linq to extract the datatable rows containg xml and
then write them to an xmldocument as xmlelements?


LINQ Code:-

Dim quotes = From quote In
frmMainQuote.quoteData.Tables("quote").AsEnumerable _
Select quote _

Where (quote.Item("category").ToString = cboCategory.SelectedItem.ToString)
_

And (quote.Item("author").ToString = txtAuthor.Text) _

And (quote.Item("text").ToString Like "*" & txtKeyword.Text & "*") _

And (quote.Item("date").ToString = dtpQuoteDate.Value.ToString("dd MMMM
yyyy"))



'WRITE OUT xmlElement to an xmlDocument:-

Dim outQuoteDoc As New XDocument(New XElement("quotefile", quotes))

'Or

Dim outQuoteDoc As New XDocument(New XElement("quotefile", quotes.tostring))



Thanks

Rob
 
R

Rob W

I have amended my LINQ however I'm still not able to retrieve the datarow
values as string though using the .Tostring conversion.

Anyone got any ideas how to extract the xml data from the datatable using
LINQ?

Dim quotes = From quote In
frmMainQuote.quoteData.Tables("quote").AsEnumerable _

Where quote.Item("category").ToString = cboCategory.SelectedItem.ToString _

And quote.Item("author").ToString = txtAuthor.Text _

And quote.Item("text").ToString Like "*" & txtKeyword.Text & "*" _

And quote.Item("date").ToString = dtpQuoteDate.Value.ToString("dd MMMM
yyyy") _

Select stringQuote = quote.ToString()
 
F

Family Tree Mike

Rob said:
I have amended my LINQ however I'm still not able to retrieve the datarow
values as string though using the .Tostring conversion.

Anyone got any ideas how to extract the xml data from the datatable using
LINQ?

Dim quotes = From quote In
frmMainQuote.quoteData.Tables("quote").AsEnumerable _

Where quote.Item("category").ToString = cboCategory.SelectedItem.ToString _

And quote.Item("author").ToString = txtAuthor.Text _

And quote.Item("text").ToString Like "*" & txtKeyword.Text & "*" _

And quote.Item("date").ToString = dtpQuoteDate.Value.ToString("dd MMMM
yyyy") _

Select stringQuote = quote.ToString()

Have you looked at the string you get from converting 'quotes' using
'ToString()'? It should be something like
'System.Data.EnumerableRowCollection`1[System.Data.DataRow]', which
isn't the xml you want, I suspect.

Which Column has the xmldata?
 
R

Rob W

Thanks for the reply.

Indeed it does read
'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' when written
out to the xml document.


The datatable is intially populated via :-
Dim xmlquotesfile As New XmlDataDocument()

xmlquotesfile.DataSet.ReadXml("file.xml")

cQuoteDataSet = xmlquotesfile.DataSet



So the datatable is based on xml data, It's a mystery to me really how the
data actually looks with the datatable.

In a for each Loop within the datatable and print out the individual
datarow columns it displays the text values inside the element tags and
never see the xml tags.

I have used the dataset readxml/write with success for other tasks.
Can I query the datatable written from an xml document and get xml output I
wonder via LINQ?

Thanks
Rob

Family Tree Mike said:
Rob said:
I have amended my LINQ however I'm still not able to retrieve the datarow
values as string though using the .Tostring conversion.

Anyone got any ideas how to extract the xml data from the datatable using
LINQ?

Dim quotes = From quote In
frmMainQuote.quoteData.Tables("quote").AsEnumerable _

Where quote.Item("category").ToString = cboCategory.SelectedItem.ToString
_

And quote.Item("author").ToString = txtAuthor.Text _

And quote.Item("text").ToString Like "*" & txtKeyword.Text & "*" _

And quote.Item("date").ToString = dtpQuoteDate.Value.ToString("dd MMMM
yyyy") _

Select stringQuote = quote.ToString()

Have you looked at the string you get from converting 'quotes' using
'ToString()'? It should be something like
'System.Data.EnumerableRowCollection`1[System.Data.DataRow]', which isn't
the xml you want, I suspect.

Which Column has the xmldata?
 
F

Family Tree Mike

Rob said:
Thanks for the reply.

Indeed it does read
'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' when written
out to the xml document.


The datatable is intially populated via :-
Dim xmlquotesfile As New XmlDataDocument()

xmlquotesfile.DataSet.ReadXml("file.xml")

cQuoteDataSet = xmlquotesfile.DataSet



So the datatable is based on xml data, It's a mystery to me really how the
data actually looks with the datatable.

In a for each Loop within the datatable and print out the individual
datarow columns it displays the text values inside the element tags and
never see the xml tags.

I have used the dataset readxml/write with success for other tasks.
Can I query the datatable written from an xml document and get xml output I
wonder via LINQ?

Thanks
Rob

Rob,

The datatable is more or less, just a set of rows and columns whether it
comes from Xml, SQL, MySQL, or SomeStrangeDbEngine... If you want to
get xml for the query, you still need to convert the data to an xml file
by using WriteXml(). If you want to write each row as if it was xml,
then you would need to create a custom output creating strings that look
like xml. I'm not really sure I understand why you would want to do
that though.

As an alternative, you could keep everthing as an XmlDocument and use
Linq to Xml. Have a look at
http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx for some
examples.
 
R

Rob W

Thanks Mike for the reply.

The requirement is to create an xml file based on search criteria based on
the form input.

I do have working code with a file but I thought it would be more efficient
to use a dataset rather than reload a file, experimenting really.

I
copied the original table structure and then added rows from the LINQ
result and wrote to an xml file
Dim dd As New DataSet

dd.Tables.Add(frmMainQuote.quoteData.Tables("quote").Clone)

For Each ee In quotes

dd.Tables("quote").ImportRow(ee)

Next

dd.WriteXml("name.xml")


I now have a valid xmlfile :)

The only downside is the root element is specified as <NewDataSet> can this
be changed?
Otherwise my schema is not going to be happy :-(

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<quote>
<date>25 November 2009</date>
<author>da</author>
<category>Careers</category>
<text>da</text>
</quote>
<quote>
<date>25 November 2009</date>
<author>da</author>
<category>Careers</category>
<text>dada</text>
</quote>
</NewDataSet>

Thanks for all the help
Rob

Family Tree Mike said:
Rob said:
Thanks for the reply.

Indeed it does read
'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' when written
out to the xml document.


The datatable is intially populated via :-
Dim xmlquotesfile As New XmlDataDocument()

xmlquotesfile.DataSet.ReadXml("file.xml")

cQuoteDataSet = xmlquotesfile.DataSet



So the datatable is based on xml data, It's a mystery to me really how
the data actually looks with the datatable.

In a for each Loop within the datatable and print out the individual
datarow columns it displays the text values inside the element tags and
never see the xml tags.

I have used the dataset readxml/write with success for other tasks.
Can I query the datatable written from an xml document and get xml output
I wonder via LINQ?

Thanks
Rob

Rob,

The datatable is more or less, just a set of rows and columns whether it
comes from Xml, SQL, MySQL, or SomeStrangeDbEngine... If you want to get
xml for the query, you still need to convert the data to an xml file by
using WriteXml(). If you want to write each row as if it was xml, then
you would need to create a custom output creating strings that look like
xml. I'm not really sure I understand why you would want to do that
though.

As an alternative, you could keep everthing as an XmlDocument and use Linq
to Xml. Have a look at
http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx for some
examples.
 
R

Rob W

Ahh Im too quick in asking for help!

Just renamed the dataset
dd.DataSetName = "Quotefile"



Thanks

Rob


Rob W said:
Thanks Mike for the reply.

The requirement is to create an xml file based on search criteria based on
the form input.

I do have working code with a file but I thought it would be more
efficient to use a dataset rather than reload a file, experimenting
really.

I
copied the original table structure and then added rows from the LINQ
result and wrote to an xml file
Dim dd As New DataSet

dd.Tables.Add(frmMainQuote.quoteData.Tables("quote").Clone)

For Each ee In quotes

dd.Tables("quote").ImportRow(ee)

Next

dd.WriteXml("name.xml")


I now have a valid xmlfile :)

The only downside is the root element is specified as <NewDataSet> can
this be changed?
Otherwise my schema is not going to be happy :-(

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<quote>
<date>25 November 2009</date>
<author>da</author>
<category>Careers</category>
<text>da</text>
</quote>
<quote>
<date>25 November 2009</date>
<author>da</author>
<category>Careers</category>
<text>dada</text>
</quote>
</NewDataSet>

Thanks for all the help
Rob

Family Tree Mike said:
Rob said:
Thanks for the reply.

Indeed it does read
'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' when
written out to the xml document.


The datatable is intially populated via :-
Dim xmlquotesfile As New XmlDataDocument()

xmlquotesfile.DataSet.ReadXml("file.xml")

cQuoteDataSet = xmlquotesfile.DataSet



So the datatable is based on xml data, It's a mystery to me really how
the data actually looks with the datatable.

In a for each Loop within the datatable and print out the individual
datarow columns it displays the text values inside the element tags and
never see the xml tags.

I have used the dataset readxml/write with success for other tasks.
Can I query the datatable written from an xml document and get xml
output I wonder via LINQ?

Thanks
Rob

Rob,

The datatable is more or less, just a set of rows and columns whether it
comes from Xml, SQL, MySQL, or SomeStrangeDbEngine... If you want to get
xml for the query, you still need to convert the data to an xml file by
using WriteXml(). If you want to write each row as if it was xml, then
you would need to create a custom output creating strings that look like
xml. I'm not really sure I understand why you would want to do that
though.

As an alternative, you could keep everthing as an XmlDocument and use
Linq to Xml. Have a look at
http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx for some
examples.
 
F

Family Tree Mike

Rob said:
Thanks Mike for the reply.

The requirement is to create an xml file based on search criteria based on
the form input.

I do have working code with a file but I thought it would be more efficient
to use a dataset rather than reload a file, experimenting really.

I
copied the original table structure and then added rows from the LINQ
result and wrote to an xml file
Dim dd As New DataSet

dd.Tables.Add(frmMainQuote.quoteData.Tables("quote").Clone)

For Each ee In quotes

dd.Tables("quote").ImportRow(ee)

Next

dd.WriteXml("name.xml")


I now have a valid xmlfile :)

The only downside is the root element is specified as <NewDataSet> can this
be changed?
Otherwise my schema is not going to be happy :-(

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<quote>
<date>25 November 2009</date>
<author>da</author>
<category>Careers</category>
<text>da</text>
</quote>
<quote>
<date>25 November 2009</date>
<author>da</author>
<category>Careers</category>
<text>dada</text>
</quote>
</NewDataSet>

Thanks for all the help
Rob

To change the document element in the output, change the DataSetName
property of the resulting dataset (dd.DataSetName = "MyDataset").
 
Top