Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft.Data.SQLite参数不起作用_C#_Sqlite_Uwp - Fatal编程技术网

C# Microsoft.Data.SQLite参数不起作用

C# Microsoft.Data.SQLite参数不起作用,c#,sqlite,uwp,C#,Sqlite,Uwp,我正在使用Microsoft.Data.SQLite构建一个数据库亭。我在生成命令时使用参数化查询。这一直有效,直到VS出现构建问题,并且在应用了各种更新(如下所述)之后,我的参数不再被应用。将值硬编码到commandText中会起作用 我以前使用的是基本的 selectCommand.Parameters.Add("@Table", Table) 我尝试使用一个更明确的参数。以下是完整的命令: public static List<String> GetTables(string

我正在使用Microsoft.Data.SQLite构建一个数据库亭。我在生成命令时使用参数化查询。这一直有效,直到VS出现构建问题,并且在应用了各种更新(如下所述)之后,我的参数不再被应用。将值硬编码到commandText中会起作用

我以前使用的是基本的

selectCommand.Parameters.Add("@Table", Table)
我尝试使用一个更明确的参数。以下是完整的命令:

public static List<String> GetTables(string Table) // Get the Items in a Table
        {
            List<String> entries = new List<string>();

            using (SqliteConnection db = new SqliteConnection(ConnectionString)) // the db
            {
                db.Open();

                SqliteCommand selectCommand = new SqliteCommand("SELECT Item FROM @Table;", db);

                selectCommand.Parameters.Add("@Table", SqliteType.Text).Value = Table;

                SqliteDataReader query = selectCommand.ExecuteReader();

                while (query.Read()) // while still reading data
                {
                    entries.Add(query.GetString(0)); // add string to entries
                }

                db.Close();
            }

            return entries;
        }
publicstaticlist GetTables(stringtable)//获取表中的项
{
列表条目=新列表();
使用(SqliteConnection db=newsqliteconnection(ConnectionString))//数据库
{
db.Open();
SqliteCommand selectCommand=newsqlitecommand(“从@Table;中选择项”,db);
选择command.Parameters.Add(“@Table”,SqliteType.Text).Value=Table;
SqliteDataReader query=selectCommand.ExecuteReader();
while(query.Read())//仍在读取数据时
{
entries.Add(query.GetString(0));//将字符串添加到条目
}
db.Close();
}
返回条目;
}
但是这个参数仍然没有被应用。以下是全部错误:

SQLite Error 1: 'near "@Table": syntax error'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.<PrepareAndEnumerateStatements>d__62.MoveNext()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()
at DataAccessLibrary.DataAccess.GetTables(String Table)
at brogle.SelectionPage.<LoadItemGridContent>d__8.MoveNext()}   Microsoft.Data.Sqlite.SqliteException
SQLite错误1:“@Table”附近:语法错误。 位于Microsoft.Data.Sqlite.SqliteException.throweexceptionforrc(Int32 rc,sqlite3 db) 在Microsoft.Data.Sqlite.SqliteCommand.d_u62.MoveNext()中 在Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior)中 位于Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()处 位于DataAccessLibrary.DataAccess.GetTables(字符串表) 在brogle.SelectionPage.d__8.MoveNext()}Microsoft.Data.Sqlite.SqliteException 显然,
@Table
没有被更改为字符串表,其值为“bulls”。(有一个表“bulls”,同样,将其硬编码到命令中会按预期工作。)调试表明命令接受值为“bulls”的参数
@Table

为了解决构建问题(代码分析抛出错误),我安装了Microsoft.CodeAnalysis.FxCopAnalyzers,将SQLitePCLRaw.bundle\u winsqlite3和Microsoft.NETCore.UniversalWindowsPlatform更新为最新版本,并将VS更新为15.9.7


如果您需要有关任何内容的更多详细信息,我可以提供。谢谢。

这是针对参数的。您不能以这种方式提供表名,您可以做的解决方法是:

SqliteCommand selectCommand = new SqliteCommand("SELECT Item FROM "+Table, db);

有关更多详细信息,请参阅官方文档。

您不能像那样参数化表名。您需要使用字符串连接将其添加到中。