Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 vjohnree25 · Dec 08, 2018 at 05:39 PM · scripting problemdatabasedatabase handling

Is there anybody who can look into my code to help me in resolving my error? Data in Database is not updating.

HI I have an issue with regards to my update function. Is there someone who can look into my code and tell me my mistake? Here is my code:

public void UpdateUser()

 {
     string OU = OldUser.text;
     string NU = NewUser.text;
     if (OU == "" || NU == "")
     {
         Debug.Log("Don't Leave Any Blank");
     }
     else
     {

         using (IDbConnection dbConn = new SqliteConnection(con))
         {
             dbConn.Open();
             using (IDbCommand dbCmd = dbConn.CreateCommand())
             {

                 string sqlQuery = string.Format("SELECT * FROM UsersInformation WHERE username = (\"{0}\")", OU);
                 dbCmd.CommandText = sqlQuery;
                 using (IDataReader reader = dbCmd.ExecuteReader())
                 {
                     if (reader.Read() == true)
                     {
                         sqlQuery = string.Format("UPDATE UsersInformation set username = (\"{0}\") WHERE username = (\"{1}\")", NU, OU);
                         Debug.Log("One User Matched");
                         dbCmd.ExecuteScalar();
                     }
                     else
                     {
                         Debug.Log("No User Matched!");
                     }

                     reader.Close();
                     dbCmd.Dispose();
                     dbConn.Close();



                 }
             }
         }
     }
 }
Comment
Add comment · Show 5
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 vjohnree25 · Dec 08, 2018 at 06:24 PM 0
Share

I transferred dbCmd.ExuteScalar(); under reader.Close(); I don't have any error now but database is not updating.

avatar image Bonfire-Boy · Dec 08, 2018 at 06:29 PM 0
Share

You construct the update query command string at line 23, but you never use it. Looks like you probably need to add dbCmd.CommandText = sqlQuery; at line 24. You do that at line 18 but that's irrelevant since you change sqlQuery afterwards.

avatar image vjohnree25 Bonfire-Boy · Dec 08, 2018 at 06:35 PM 0
Share

An error occur, unity says "Cannot set CommandText while a DataReader is Active"

avatar image Bonfire-Boy vjohnree25 · Dec 08, 2018 at 06:45 PM 0
Share

Ah yes, that'll be because you're trying to use dbCmd for something else while you're still using it. Just make a second call to CreateCommand so as to avoid that

avatar image vjohnree25 Bonfire-Boy · Dec 08, 2018 at 06:43 PM 0
Share

SIR thank you :) problem solved

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

171 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 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 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 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 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 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 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 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

Looking for step-by-step manual how to configure SQL Lite on Unity 2017 ( or other database) 1 Answer

Firebase with Unity instantiate new data 1 Answer

Unity/C#/MongoDB - attempt to read past the end of the stream? 0 Answers

what database should i use 3 Answers

problem updating info to data base 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