Add InsertCommand to dataAdapter with SqliteCommandBuilder

I'm trying to generate InsertCommand to SqliteDataAdapter but got this error:

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

This is my code:

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 script:

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

Data in table

1 'Pedro'

Any help?

Answers

  • Tracy320Tracy320 Member ✭✭

    Could you please post a basic demo so that we can test it ?

  • jezhjezh Member, Xamarin Team Xamurai

    What's the Nuget package of Sqlite you used in your app?

Sign In or Register to comment.