Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Serialize Dataset to Json and back
Message
 
 
À
24/11/2015 10:33:22
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01627834
Message ID:
01627844
Vues:
39
>>>>>>Hi,
>>>>>>
>>>>>>I have been Googling on the topic of how to serialize a dataset to JSon, then store it in the local storage and then convert it back to the dataset.
>>>>>>
>>>>>>In some posts I see people use JsonConvert() and in some other cases there is a code to "manually' convert dataset to a string. Which method is more efficient, in your opinion? In one thread (on Stackoverflow) the person says that JsonConvert() stores the column name for each column and each row into a string. This seems to be a pretty big waste of storage (given that the local storage is limited).
>>>>>>What do you think?
>>>>
>>>>Firstly I wouldn't try to convert a dataset to Json - use as simple a class as possible. Don't know if you are using EF - that provides an easy way for this.
>>>>
>>>>WebApi automatically used NewtonSoft.Json to convert C# objects to Json if that type is requested (or set as the default type). The column name has to be repeated for each property - that's the nature of Json. In practice it's not a problem - still more compact to send over the wire than XML.
>>>>
>>>>I'm routinely storing arrays of 200~ objects (each with 10-12 properties) in local storage on the browser under one key. Only problem is that if you want to modify one object you have to load them all, make the change, and re-save - but again I've not found it too process intensive.
>>>>
>>>>HTH,
>>>>Viv
>>>
>>>I looked at my code (which I have done years ago) and here is what I have (simplified):
>>>
>>>1. Creating SQL Data adapter:
>>>
>>> idbAdapter = new SqlDataAdapter(sqlSelectString, connectionString);
>>>
>>>
>>>2. Fill dataset from the data adapter:
>>>
>>>DataSet oDataSet = new DataSet();
>>>objAdapter.Fill(oDataSet);
>>>
>>>
>>>Do you think I can skip step 2 and convert data adapter to JSON?
>>
>>I am re-reading your message, the paragraph of storing arrays to local storage. Maybe, instead of Filling dataset, I can fill an array? Then store the array to the local storage. (I am just talking to myself :)
>
>Haven't used a SQLDataAdapter in yonks - but, IIRC, it only creates datasets. You could probably use a DataReader but that won't help much if you need to write back to the DB.
>
>You could continue with the DataAdapter and write methods to create simple objects from the rows and also to populate a dataset from objects returned from the browser - but it would probably be simpler to bite the bullet and use EF for objects which need to be converted to JSON.

My issue with EF (right now) is that I would have to introduce another "new" technology (for me :) into this project. And I am trying to make simply changes to my "current" project.

Speaking about converting dataset to JSON. The possible inefficiency of this process (meaning time it takes) is not critical for me. Since a user will only use it once in a long while (lookup data does not change often). What IS important for me is that at run-time my code can get the data from the localstorage, quickly, convert to dataset and bind to the drop-down. You see what I mean?

Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform