B
B
beduin012016-04-21 15:52:16
SQL
beduin01, 2016-04-21 15:52:16

Why doesn't the following Prepared query work?

For some reason, substitution in the following sql query does not work:

foreach (var table in existsInDBTables)
            {
                Console.WriteLine("------>{0}", table);
                Console.ReadKey();                
                SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=" + config.SQLLitePath + ";Version=3;");
                m_dbConnection.Open();

                SQLiteCommand command = new SQLiteCommand(m_dbConnection);
                command.CommandText = "SELECT 1 FROM @table LIMIT1";
                command.Parameters.AddWithValue("@table", table);
                command.Prepare();

Tried to do the same:
command.Parameters.AddWithValue("@table", "bar");
At the output, I persistently get:
near "@table": syntax error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-04-21
@k1lex

You are trying to pass a table as a parameter. In my practice, this is not very possible.
In this case, I form a temporary hut on the server in the transaction, transfer it to the table and then do the required operations.
But now, looking at your code, I don’t really understand why to transfer the table to the server in order to make a SELECT from it by the server.
Maybe it's easier to use LINQ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question