Write Dataset to Database Field

  • Thread starter Thread starter DotNetJunkies User
  • Start date Start date
D

DotNetJunkies User

Hi all,

I have a question on how can I write the entire Dataset to a NTEXT field of SQLServer.

Can anyone help me?

Thanks!

/mike
 
Hi

I do not know if a NTEXT field is large enough, however to make a String
from a dataset you can use dataset GetXML.

One of my wishes is that there was a dataset SetXML because you while have
to loop through it as an XMLdoc to get it back to a dataset as far as I
know.

Or maybe Jon has a solution for that last as a specialis in my opinion for
serialization (I am seriously strugling with that Jon, maybe a nice chalenge
for you when you see this, I can also serialize it real as a datset with one
of the 3 schematypes in it, but also not deserialize that. Where I am not
talking about doing it with dataset.writexml and readxml via disk that is a
piece of cake).

Cor
 
I do not know if a NTEXT field is large enough, however to make a Strin
from a dataset you can use dataset GetXML

To quote SQL Server Books OnLine "NTEXT is Variable-length Unicode data with a maximum length of 230 - 1 (1,073,741,823) characters
One of my wishes is that there was a dataset SetXML because you while hav
to loop through it as an XMLdoc to get it back to a dataset as far as
know

Look at WriteXML/ReadXML of the dataset using StringReader. Here is an example from the MSDN documents

If Page.IsPostBack The
Dim sr as New System.IO.StringReader(CStr(ViewState("dsCustomers"))
DsCustomers1.ReadXml(sr
Els
SqlDataAdapter1.Fill(DsCustomers1
Dim sw as New System.IO.StringWriter(
DsCustomers1.WriteXml(sw
ViewState("dsCustomers") = sw.ToString(
End I

----- Cor Ligthert wrote: ----

H

I do not know if a NTEXT field is large enough, however to make a Strin
from a dataset you can use dataset GetXML

One of my wishes is that there was a dataset SetXML because you while hav
to loop through it as an XMLdoc to get it back to a dataset as far as
know

Or maybe Jon has a solution for that last as a specialis in my opinion fo
serialization (I am seriously strugling with that Jon, maybe a nice chaleng
for you when you see this, I can also serialize it real as a datset with on
of the 3 schematypes in it, but also not deserialize that. Where I am no
talking about doing it with dataset.writexml and readxml via disk that is
piece of cake)

Co
 
oops that should be
"NTEXT is Variable-length Unicode data with a maximum length of 2^30 - 1 (1,073,741,823) characters

----- Jeff wrote: ----
I do not know if a NTEXT field is large enough, however to make a Strin
from a dataset you can use dataset GetXML

To quote SQL Server Books OnLine "NTEXT is Variable-length Unicode data with a maximum length of 230 - 1 (1,073,741,823) characters
One of my wishes is that there was a dataset SetXML because you while hav
to loop through it as an XMLdoc to get it back to a dataset as far as
know

Look at WriteXML/ReadXML of the dataset using StringReader. Here is an example from the MSDN documents

If Page.IsPostBack The
Dim sr as New System.IO.StringReader(CStr(ViewState("dsCustomers"))
DsCustomers1.ReadXml(sr
Els
SqlDataAdapter1.Fill(DsCustomers1
Dim sw as New System.IO.StringWriter(
DsCustomers1.WriteXml(sw
ViewState("dsCustomers") = sw.ToString(
End I


----- Cor Ligthert wrote: ----

H

I do not know if a NTEXT field is large enough, however to make a Strin
from a dataset you can use dataset GetXML

One of my wishes is that there was a dataset SetXML because you while hav
to loop through it as an XMLdoc to get it back to a dataset as far as
know

Or maybe Jon has a solution for that last as a specialis in my opinion fo
serialization (I am seriously strugling with that Jon, maybe a nice chaleng
for you when you see this, I can also serialize it real as a datset with on
of the 3 schematypes in it, but also not deserialize that. Where I am no
talking about doing it with dataset.writexml and readxml via disk that is
piece of cake)

Co
 
Hi Jeff,

This serializing works greath it is in my opinion I have narrowed it down to
\\\
Dim sw As New System.IO.StringWriter
ds1.WriteXml(sw)
Dim mystring As String = sw.tostring
Dim sr As New System.IO.StringReader(mystring)
Dim ds2 As New DataSet
ds2.ReadXml(sr)
///
Thanks, maybe it helps you when I say that your code to serialize for the
viewstate can in my opinion direct, it needs no serializer.

Try it, I do not know if it is faster.

However thank you very much again because I have long searched for this
simple solution of serialization a dataset to a string

Cor

For the viewstate, the session goes the same
\\\
If Not IsPostBack Then
ViewState("dataset") = ds
End If
///
\\\
ds = DirectCast(ViewState("dataset"), DataSet)
///
 
Thanks, maybe it helps you when I say that your code to serialize for th
viewstate can in my opinion direct, it needs no serializer

Its definitely easier to set the reference directly but this was an example direct from the MSDN. Easy to copy and paste:

Performance wise though, its probably the same. When a dataset is asked to serialize/deserialize itself, it does it through XML serialization

----- Cor Ligthert wrote: ----

Hi Jeff

This serializing works greath it is in my opinion I have narrowed it down t
\\ Dim sw As New System.IO.StringWrite
ds1.WriteXml(sw
Dim mystring As String = sw.tostrin
Dim sr As New System.IO.StringReader(mystring
Dim ds2 As New DataSe
ds2.ReadXml(sr
//
Thanks, maybe it helps you when I say that your code to serialize for th
viewstate can in my opinion direct, it needs no serializer

Try it, I do not know if it is faster

However thank you very much again because I have long searched for thi
simple solution of serialization a dataset to a strin

Co

For the viewstate, the session goes the sam
\\ If Not IsPostBack The
ViewState("dataset") = d
End I
//
\\ ds = DirectCast(ViewState("dataset"), DataSet
//
 
Back
Top