Answer the question
In order to leave comments, you need to log in
Oddities in the work of SQLite in C #: why is the query with a parameter not executed correctly?
Here is an example of code that does not execute correctly
cmd = conn.CreateCommand();
cmd.CommandText = "SELECT @s FROM Cars";
cmd.Parameters.Add("@s", DbType.String).Value = "Id";
r = cmd.ExecuteReader();
while (r.Read())
{
MessageBox.Show(r.GetValue(0).ToString());
//MessageBox.Show(r["Id"].ToString());
}
r.Close();
1
2
3
4
5
Answer the question
In order to leave comments, you need to log in
It will not work with SQL parameters to set the names of the columns in SQL.
At you as a result the request
which and was executed turned out. As you asked: SQL selected records from the Cars table (5 records) and returned the string 'id' for each as you requested.
There is no id column in the query. There is an unnamed column. Therefore, an attempt to return a column that does not exist results in an IndexOutOfBoundsException.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question