Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Add InsertCommand to dataAdapter with SqliteCommandBuilder

$
0
0

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?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>