|
Post by nicoolorem on Feb 13, 2022 16:53:52 GMT
Hello, I have this code: public void PickAWord(){ // Gather a list of words pulled from the words table List<Word> wordList = dbManager.Query<Word>(SqlRandomWord);
// output the list of words
foreach (Word wordRecord in wordList) { QuestionValue = wordRecord.spanish; QuestionTxt.text = QuestionValue; } } and I would like to be able to manage several languages with a variable called "Lang". Lang can be "spanish", "french", "english"... and in my DB, I have a column for each language. My question is : How can I write this loop to use a Lang variable? I tried something like this where Lang is the variable to select which lang the user selected: public void PickAWord(){ Lang = "spanish"; List<Word> wordList = dbManager.Query<Word>(SqlRandomWord); foreach (Word wordRecord in wordList) { QuestionValue = wordRecord.Lang; QuestionTxt.text = QuestionValue; } } obviously it doesn't work but that's the idea of what I'm trying to do. Can you help me please? Thank you!
|
|
|
Post by nicoolorem on Feb 15, 2022 10:30:23 GMT
Hello! Any help please?
|
|
|
Post by echo17 on Feb 15, 2022 13:43:25 GMT
I'm not certain of your schema, but one idea might be:
public void PickAWord(){ Lang = "spanish"; var sql = "SELECT " + Lang + " FROM MyTable"; var wordTable = dbManager.QueryGeneric(sql); foreach (SimpleSQL.SimpleDataRow dr in wordTable.rows) { QuestionValue = dr[0].ToString(); QuestionTxt.text = QuestionValue; } }
I haven't tested this code, but you get the idea. Just use a generic query to pull a table without ORM. That way you can pull the columns by index instead of by an object name.
|
|
|
Post by nicoolorem on Feb 16, 2022 18:54:17 GMT
Hello @echo17,
Thank you for your answer and the solution you provided. The good news is that it's working like a charm on Unity Player. The bad one is that now, the app isn't working when I test it on Android device (Galaxy S8). It looks like the link with the database is broken, data is not loaded but only when I test it on device. Any idea why? 😬
Thanks again for your help!
|
|
|
Post by nicoolorem on Feb 17, 2022 5:53:52 GMT
Hello @echo17! Me again Never-mind my previous message, everything is working like a charm! It wasn't working on Android anymore due to a silly move I did a a few days ago : I deleted the Android folder from the Plugins folder, that's why. Thank you again!
|
|