Why doesn't UPDATE c#?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
8 views
I have a query in database SQLite:
UPDATE products SET manager = ( SELECT user FROM brandUsers WHERE firstCom IS NOT NULL AND prodBrand = brandUsers.brand AND firstCom = brandUsers.user ) WHERE manager IS NULL AND firstCom IS NOT NULL;


It perfectly fulfills without errors, and updates the data in SQLiteStudio,
but when I run this code in VS, nothing is updated:
using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};", dbPath))) { string sqlCom = $@"UPDATE products SET manager = ( SELECT user FROM brandUsers WHERE firstCom IS NOT NULL AND prodBrand = brandUsers.brand AND firstCom = brandUsers.user ) WHERE manager IS NULL AND firstCom IS NOT NULL"; connection.Open(); SQLiteCommand command = new SQLiteCommand(sqlCom, connection); try { command.ExecuteNonQuery(); connection.Close(); return true; } catch { File.AppendAllText(Environment.CurrentDirectory + @"\\SQLError.txt", DateTime.Now.ToString() + "\\t" + sqlCom + Environment.NewLine); connection.Close(); return false; } }


All brain broke, can't understand what could be the problem?
by | 8 views

4 Answers

0 like 0 dislike
prodBrand = brandUsers.brand

just a string, you must either string.Format(), or interpolation to use, either command settings (which is best)
by
0 like 0 dislike
Maybe you need the semicolon at the end of the expression?
by
0 like 0 dislike
In the catch block, add the Exceprion when you debug and run this code and view the error message.
Just if the query works fine in SQLiteStudio, it may get you a connection fails?
by
0 like 0 dislike
Don't know still true or not. The first thing to check is whether auto-commit or not. Should be enabled by default.
sqlite3_get_autocommit
Second, the subquery must always return a scalar value (a single value for each row).
You can use the Update method from sqlliteconnection. updates
there is a package in nuget sqllite-net-pcl ,
well, it does in a pinch.
Better to use parameterized query and try to break your request into two : select and update.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Mar 21, 2019 by v1z
0 like 0 dislike
2 answers
0 like 0 dislike
4 answers
asked May 20, 2019 by val_gr
110,608 questions
257,186 answers
0 comments
28,151 users