Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CaKeMeaT · Jul 07, 2015 at 08:29 PM · sql

deserialize an XML object returned from SQL query?

I need to deserialize an XML object that 'should' be returned from a SQL query.

I had this working in JSON, but cannot use JSON so I am moving over to XML. The JsonConvert functionality gets my result in one line.. but I am not really sure how to handle what SQL gives me.

When writing to the server the Table is getting an Xdocument type, into a xml datatype cell.

             if (do_sql_read)
             {
                 List<string> usernames = new List<string>();
                 List<int> ids = new List<int>();
                 string sql_load;
 
                 
 
                 Player player_after_load = new Player();
 
                 //single
                 string select_string = @"SELECT @seek_id FROM [Table]";
 
                 //multiple
                 //string select_string = @"SELECT * FROM [Table]";
 
                 using (SqlConnection sql_connection_a = new SqlConnection( GetConnectionString() ) )
                 {
                     sql_connection_a.Open();
 
                     using (SqlCommand command = new SqlCommand(select_string, sql_connection_a))
                     {
                         // single (remove if using the multiple results string)
                         command.Parameters.Add("@seek_id", SqlDbType.Int, 5).Value = tmp_id; // needed?
                         SqlDataReader reader = command.ExecuteReader(CommandBehavior.Default);
 
                         // XML VERSION
                         while (reader.Read())
                         {
                             int iii = reader.GetInt32(0);    // unique id int
                             string name = reader.GetString(1);  // Name string
                             sql_load = reader.GetString(2);
                             usernames.Add(name);
                             ids.Add(iii);
 
                             // ###
                             XmlSerializer XML_serializer = new XmlSerializer (typeof(Player));
 
                             player_after_load = (Player)XML_serializer.Deserialize (sql_load);
 
                             Console.WriteLine("SQLPlayer:  " + iii + " " + player_after_load.name + " " + player_after_load.health + " " + player_after_load.mana);
 
                         }
 
 
                         /* JSON VERSION
                         while (reader.Read())
                         {
                             int iii = reader.GetInt32(0);    // unique id int
                             string name = reader.GetString(1);  // Name string
                             sql_load = reader.GetString(2);
                             usernames.Add(name);
                             ids.Add(iii);
 
                             player_after_load = JsonConvert.DeserializeObject<Player>(sql_load);
                             Console.WriteLine("SQLPlayer:  " + iii + " " + player_after_load.name + " " + player_after_load.health + " " + player_after_load.mana);
                         }
                         */
                     }
                 }
         
             } // end do_sql_string
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jul 07, 2015 at 09:53 PM 0
Share

Uhm, why can't you use JSON? JSON is a simpler and usually a more lightweight format. If the data don't need to be human readable it's quite common to have everything in one line (in both JSON and X$$anonymous$$L). That would be just unnecessary whitespace.

Besides that your query strings look a bit strange. I think this might be your actual problem... A select statement looks like this:

 SELECT (column names) FRO$$anonymous$$ (tablename)

So between SELECT and FRO$$anonymous$$ you specify which columns from the table you want. If you don't add a WHERE clause at the end it will always return all rows. A "*" simply means all columns.

$$anonymous$$y guess is your "single" query should look like this:

 "SELECT * FRO$$anonymous$$ [table] WHERE NameOfYourIDColumn=@seek_id"

NameOfYourIDColumn is the name of the column that should match your given value. Since we don't have your table layout we can't tell you that name ^^.

What kind of database is that? IÄm just curious since you direct connect to it. Is it a mysql, mssql, postgresql or a sqlite database? There are some $$anonymous$$or differences between those. Your table name also looks strange ^^

avatar image CaKeMeaT · Jul 07, 2015 at 10:26 PM 0
Share

Targetting for Windows Phone and Unity.. Newtonsoft.json is not supported, System.IO is also not.

Complicates things for sure...

avatar image Bunny83 · Jul 08, 2015 at 09:10 AM 0
Share

Well, i don't have a windows phone ^^. Ok using X$$anonymous$$L shouldn't be any different from the workflow. Have you checked what your query actually returned? Is it X$$anonymous$$L? Have you checked the db entry with external db management software to see if the data arrived there as it should?

At the moment you just say "It doesn't work" but we don't know what you have tried so far...

Also have you read my comment about your queries? It's also still not clear which database you're using.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Uploading custom filetype to MySQL database 1 Answer

Access a MySQL database via C# ? 2 Answers

Which is faster Update vs Delete Insert in Unity3d Database 1 Answer

[Quiz game] How do I make players contribute with questions? 1 Answer

Getting Specific mySql Row by searching table with a name 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges