|
-
Feb 4th, 2013, 12:48 AM
#1
Thread Starter
Hyperactive Member
xml serilaization
Hello, in my program i allow users to create templates which is entered into a datagridview. and i guess the best approach to save it is to serialize the datatable into a string and save it to an SQL xml datafield. is this achievable w/out having to write into an external file. thanks
-
Feb 4th, 2013, 01:18 AM
#2
Re: xml serilaization
Hi,
If I understand your question correctly then the simple answer is No. If you want to use stored information in your project, which in not hardcoded, then this stored information has to come from an external data file in one form or another.
In the case of XML, if you bind your DataGridView to a DataSet/DataTable you can then use the WriteXML method of those objects to save your information. Have a look here:-
http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
Hope that helps.
Cheers,
Ian
-
Feb 4th, 2013, 02:26 PM
#3
Re: xml serilaization
Here's an example of serializing a DataTable to a string.
Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'create table
Dim testDataTable As New DataTable("MyTable")
testDataTable.Columns.Add("SomeColumn", GetType(String))
'populate table
testDataTable.Rows.Add(New Object() {"some data"})
'write xml to memory stream
Dim stream As New IO.MemoryStream
testDataTable.WriteXml(stream)
'convert memory stream into string
Dim xmlString = ConvertStreamToString(stream)
End Sub
Private Function ConvertStreamToString(stream As IO.MemoryStream) As String
stream.Position = 0
Using reader = New IO.StreamReader(stream)
Return reader.ReadToEnd
End Using
End Function
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Feb 4th, 2013, 02:33 PM
#4
Re: xml serilaization
If you want to use stored information in your project, which in not hardcoded, then this stored information has to come from an external data file in one form or another.
Er .... you might want to rethink that a bit!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Feb 4th, 2013, 05:12 PM
#5
Re: xml serilaization
The question was if the data could be stored in the database w/o having to use an intermediary file for the XML ... yes... by using the stream as wild_bill has shown...
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|