Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am converting the dataset object into xml string & then passing it through socket to some client.

On the client side when the string is received & I convert the string back into dataset object & use that object as datasource for datagrid it gives me error "Root element is missing".

Code to convert datasetinto xml string:

VB
Public Shared Function ConvertObjectToByte(ByVal ds As DataSet) As String

        Dim byReturn As String = Nothing
        Dim sStream As IO.MemoryStream = Nothing

        Dim sw As New StringWriter()
        ds.WriteXml(sStream)
        byReturn = sStream.ToString()
        Return byReturn
    End Function



Code to convert string back into dataset object:

ds.ReadXml(New System.IO.StringReader(response))

Note: response is the string that I received through socket.


Any help or suggestion would definitely be appreciated.
Posted
Updated 20-Apr-11 3:11am
v2
Comments
Dave Kreskowiak 20-Apr-11 9:26am    
Stop posting the same question over and over again. You're apparently not responding to the people who are trying to answer your question. Reply to the original answers to your questions so there is a discussion that can work out a problem.
Sandeep Mewara 20-Apr-11 9:54am    
And again!!! 3rd time or 4th?

1 solution

Hi don't repost your question again and again.

Your code has many errors basically.

ds.WriteXml(sStream) won't work. WriteXml method only works with FileStreams.

byReturn = sStream.ToString() what you want to do here?

Your method says convert to byte but it returns a string. Do you understand you are confusing people here?

However if your aim is to get the xml string from data set then use the dataset's getXml() function (string resultString=ds.GetXml();). If you want to convert that string to bytes then use byte[] bytes=Encoding.Unicode.GetBytes(resultString);. If bytes back to string then string resultString1 = Encoding.Unicode.GetString(bytes);.

XML string back to Dataset

C#
TextReader reader = new StringReader(resultString1);
       DataSet ds1 = new DataSet();
       ds1.ReadXml(reader);


It is unclear how you transfer your byte or string to another client. So that is your headache. if you transfer the right data and get right data it will work fine.

Good luck.
 
Share this answer
 
v2
Comments
Pritam N. Bohra 24-Apr-11 8:32am    
Thanks
I used dataset.getXML method & converted dataset into xml string and then passed the same through socket to the client program. On the client side when I converted the string back into dataset object I got a runtime error "Root element missing". I have no idea why I am facing this problem. Please suggest something.
Albin Abel 24-Apr-11 11:32am    
Could you find the difference in the sent string and the received string at the client side?. If no difference then post your xml string here.
Sandeep Mewara 27-Apr-11 12:08pm    
Good answer. 5!
Albin Abel 27-Apr-11 12:15pm    
I think OP hasn't solved the issue yet. Thanks for your voting
Sandeep Mewara 27-Apr-11 12:17pm    
Well, you cannot write the full code for him! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900