使用SqliteCommandBuilder将InsertCommand添加到dataAdapter

时间:2019-01-23 18:29:34

标签: sqlite

我正在尝试将插入命令生成为SqliteDataAdapter,但出现此错误:

Unhandled Exception:

System.InvalidOperationException: Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information.

这是我的代码:

using Mono.Data.Sqlite; 

public void Test(){
  var dataAdapter = new SqliteDataAdapter();
  var dataSet = new DataSet("TestTable");

  SqliteCommandBuilder commandBuilder = new SqliteCommandBuilder(dataAdapter);

  SqliteConnection connection = new SqliteConnection();
  connection.ConnectionString = "Data Source=" + dbPath;
  connection.Open();

  dataAdapter.SelectCommand = connection.CreateCommand();
  //dataAdapter.SelectCommand.CommandText = "SELECT * FROM TestTable";
  dataAdapter.SelectCommand.CommandText = "SELECT [ID], [Name] FROM TestTable";

  dataAdapter.InsertCommand = commandBuilder.GetInsertCommand(); // ERROR
}

创建表脚本:

CREATE TABLE `TestTable` (
    `ID`    INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    `Name`  TEXT NOT NULL
);

表格中的数据

1  'Pedro'

0 个答案:

没有答案