I'm evaluate different ways to connect postgresql and your product looks really good for me. But there are still some questions.
First when i will update my database from a table i need allways to set the PgsqlCommand property UpdateRowSource to NONE. Why do i need to do this?
Second, i'm not sure whats about this problem. When i create a insert command with the PgsqlCommand object and then set this command object to the Pgsql DataAdapter i receive allways a command text null reference exception. This error does not occure if i initialize the DataAdapter with a SELECT command and set the command object by the InsertCommand property?
Code: Select all
DataSet ds = new DataSet("Test");
DataTable dt = new DataTable("MyTable");
dt.Columns.Add("test");
dt.Rows.Add("Franz");
dt.Rows.Add("Hans");
dt.Rows.Add("Elke");
dt.Rows.Add("Martin");
ds.Tables.Add(dt);
PgSqlConnection conn = new PgSqlConnection("User Id=postgres;Password=pypwd;Host=localhost;Database=TestDb;Schema=public;");
conn.Open();
PgSqlCommand cmd = new PgSqlCommand("INSERT INTO \"Testtable\"(\"Name\") VALUES(?)");
cmd.Parameters.Add(":p1", PgSqlType.VarChar, 10, "test");
cmd.Connection = conn;
cmd.UpdatedRowSource = UpdateRowSource.None;
cmd.Connection = conn;
//generate null reference exception
try
{
PgSqlDataAdapter da1 = new PgSqlDataAdapter(cmd);//"SELECT * FROM \"Testtable\"",conn);
//da.InsertCommand = cmd;
da1.RowUpdating += new PgSqlRowUpdatingEventHandler(da_RowUpdating);
da1.Update(ds.Tables[0]);
}
catch (Exception e1)
{
Console.WriteLine(e1.Message);
}
//works fine
try
{
PgSqlDataAdapter da2 = new PgSqlDataAdapter("SELECT * FROM \"Testtable\"",conn);
da2.InsertCommand = cmd;
da2.RowUpdating += new PgSqlRowUpdatingEventHandler(da_RowUpdating);
da2.Update(ds.Tables[0]);
}
catch (Exception e2)
{
Console.WriteLine(e2.Message);
}
marc[/code]