【问题标题】:System.Data.SQLite parameters not being substitutedSystem.Data.SQLite 参数未被替换
【发布时间】:2011-08-20 08:24:14
【问题描述】:
            conn = new SQLiteConnection("Data Source=nk.db");
            var items = from n in internalMap.storage select n.paramName;
            conn.Open();

            cmd = new SQLiteCommand("CREATE TABLE @table_name (name TEXT)",conn);

            //create table for the index

            cmd.Parameters.AddWithValue("@table_name", j);



            cmd.ExecuteNonQuery();

当这行被执行时“cmd.ExecuteNonQuery();”我得到以下异常

“\“@table_name\”附近的 SQLite 错误:语法错误”

我所做的所有搜索似乎都表明您就是这样做的。

不知道怎么回事

【问题讨论】:

    标签: c# sql sqlite


    【解决方案1】:

    在我使用过的大多数数据库中,DDL 命令不能像这样参数化,甚至 DML 语句也不能通过表名(或字段名等)参数化。一般只有表达式值可以参数化。

    在大多数情况下,这没关系,因为您通常没有用户提供的数据,例如名称中的表格,并且没有格式考虑因素,例如数字和日期/时间等内容...所以 SQL 语句中的纯字符串替换可能是你能做的最好的,尽管它可能很丑。

    【讨论】:

      猜你喜欢
      • 2010-10-19
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多