[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

"Udfordring" med C# & Npgsql (dataadapter's og datasets)



Jeg har forgæves forsøgt at få de eksempler der ligger på Npgsql's
dokumentationssider til at virke.
Eksemplerne uden dataadapters & dataset's virker okey - men jeg kan
godt se fordelen i en semiautomatisk håndtering af "live data" vs. data
i databasen.

Er der nogen som kender til tutorials / dokumentation der bruger
C#(Mono) og Npgsql - og ikke mindst som virker?



F.eks. fejler dette lille eksempel :

using System;
using System.Data;
using Npgsql;

public class NpgsqlUserManual
{
  public static void Main(String[] args)
  {
    NpgsqlConnection conn = new
NpgsqlConnection("Server=10.1.1.110;Port=5432;User
Id=mytest;Password=mypasswd;Database=mytestdb;"); 
conn.Open(); 
DataSet
ds = new DataSet(); 
    NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from
tableb", conn); 
    da.InsertCommand = new NpgsqlCommand("insert into
tableb(field_int2, field_timestamp, field_numeric) " + " values
(:a, :b, :c)", conn); 
    da.InsertCommand.Parameters.Add(new NpgsqlParameter("a",
DbType.Int16)); 
    da.InsertCommand.Parameters.Add(new NpgsqlParameter("b",
DbType.DateTime)); 
    da.InsertCommand.Parameters.Add(new NpgsqlParameter("c",
DbType.Decimal)); 
    da.InsertCommand.Parameters[0].Direction = ParameterDirection.Input;
    da.InsertCommand.Parameters[1].Direction = ParameterDirection.Input;
    da.InsertCommand.Parameters[2].Direction = ParameterDirection.Input;
    
    da.InsertCommand.Parameters[0].SourceColumn = "field_int2";
    da.InsertCommand.Parameters[1].SourceColumn = "field_timestamp";
    da.InsertCommand.Parameters[2].SourceColumn = "field_numeric";
    
    da.Fill(ds);
    
    DataTable dt = ds.Tables[0];
    
    DataRow dr = dt.NewRow();
    dr["field_int2"] = 4;
    dr["field_timestamp"] = new DateTime(2003, 03, 03, 14, 0, 0);
    dr["field_numeric"] = 7.3M;
    
    dt.Rows.Add(dr);
    
    DataSet ds2 = ds.GetChanges();
    
    da.Update(ds2);
    
    ds.Merge(ds2);
    ds.AcceptChanges();

    conn.Close();
  }
}


Databasen findes - tabellen findes :
\d tableb
                   Table "public.tableb"
     Column      |            Type             | Modifiers 
-----------------+-----------------------------+-----------
 field_int2      | smallint                    | 
 field_timestamp | timestamp without time zone | 
 field_numeric   | numeric                     | 


Fejlen ved kørslen er :
Unhandled Exception: System.Data.ConstraintException: Failed to enable
constraints. One or more rows contain values violating non-null,
unique, or foreign-key constraints. at
System.Data.Constraint.ThrowConstraintException () [0x00000] at
System.Data.DataSet.InternalEnforceConstraints (Boolean value, Boolean
resetIndexes) [0x00000] at System.Data.DataSet.set_EnforceConstraints
(Boolean value) [0x00000] at System.Data.MergeManager.Merge
(System.Data.DataSet targetSet, System.Data.DataSet sourceSet, Boolean
preserveChanges, MissingSchemaAction missingSchemaAction) [0x00000] at
System.Data.DataSet.Merge (System.Data.DataSet dataSet, Boolean
preserveChanges, MissingSchemaAction missingSchemaAction) [0x00000] at
System.Data.DataSet.Merge (System.Data.DataSet dataSet) [0x00000] at
NpgsqlUserManual.Main (System.String[] args) [0x00000] 


Mit gæt er at parametrene i da.InsertCommand ikke fungerer korrekt...
Men da dette er taget fra den officielle dokumentation på Npgsql's
webside burde det vel virke...

Jeg overvejer stærkt at gå tilbage til Comal80!...


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2008-03-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *