I've stumbled on either the depth of my own ignorance or a fairly
serious problem when using the Firebird .NET Client in a WPF app. It
seems there's something wrong with the columns that get built during
FbDataAdapter.Fill(DataTable). The columns do not seem to support data
binding properly. Specifically, UI elements don't get updated when
values in the column change. The example code I've provided
demonstrates that columns created prior to Fill and columns created
after Fill both work as expected, but columns created during Fill do
not. The example also shows that if you fill the DataTable from a SQL
Server source with everything else kept the same, columns created
during Fill work as expected.

To run the project you'll need to provide some connection string info
and modify the query to return a few rows of string data with a field
named LastName. You may also need to drop in a reference to the
Firebird Client assembly which I removed so as not to send any
binaries.

When the interface comes up, alter any value in the third column and
tab away. The expectation is that the value in the fourth column will
reflect the change, but for me it doesn't. I'm running against a 2.1.4
server. If you alter the value in either the first or second column
and tab away, the other column is updated.

The example project source can be downloaded here:
https://msedd.com/LinkClick.aspx?fileticket=EcRAVG14WA8%3d&portalid=0

I've pasted in the relevant parts below. The MainWindow XAML:

<Window x:Class="FirebirdWPFBug.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation";
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml";
        Title="MainWindow" Height="350" Width="525">
    <Grid>
      <ItemsControl ItemsSource="{Binding COEStudents}">
         <ItemsControl.ItemTemplate>
            <DataTemplate>
               <Grid>

<Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions>
                  <TextBox Text="{Binding [Foo]}" Grid.Column="0"/>
                  <TextBox Text="{Binding [Foo]}" Grid.Column="1"/>
                  <TextBox Text="{Binding [LastName]}" Grid.Column="2"/>
                  <TextBox Text="{Binding [LastName]}" Grid.Column="3"/>
               </Grid>
            </DataTemplate>
         </ItemsControl.ItemTemplate>
      </ItemsControl>
    </Grid>
</Window>

The MainWindow code behind:

namespace FirebirdWPFBug {
   public partial class MainWindow: Window {
      public MainWindow() {
         InitializeComponent();
         DataContext=new COEVM();
      }
   }

   public class COEVM {
      DataTable coeStudTable;

      public DataView COEStudents { get { return coeStudTable.DefaultView; } }

      public COEVM() {
         coeStudTable=new DataTable();

         // The test is simply to run the project, change a value in
the third column, tab away, and
         // note that the fourth column (which is bound to the same
DataColumn) does not update. Making
         // a change to the first or second column will cause the
other to update.

         // Uncomment these lines to run with SQL Server. You'll need
to point to an existing database and
         // provide a query that produces a few rows of data with a
column named LastName.
         //System.Data.SqlClient.SqlDataAdapter adapter=
         //   new System.Data.SqlClient.SqlDataAdapter(
         //      "select top 3 LastName from HRRM",
         //      @"Data Source=localhost\SQLEXPRESS;Initial
Catalog=Viewpoint2;Integrated Security=True");

         // In the FbConnection below, you'll need to provide a value
for "initial catalog", "user id", and
         // "password". You'll also need to provide a query that
produces a few rows of data with a column
         // named LastName.
         // Comment out these lines to use the SQL Server test above.
         FirebirdSql.Data.FirebirdClient.FbConnection conn=new
FirebirdSql.Data.FirebirdClient.FbConnection(
            @"dialect=3;charset=NONE;connection lifetime=0;connection
timeout=15;pooling=True;"+
            "packet size=8192;initial
catalog=localhost:c:\\Users\\kdonn\\DBs\\NE\\MIS2000.fdb;"+
            "server type=Default;user id=userid;password=password");
         FirebirdSql.Data.FirebirdClient.FbDataAdapter adapter=
            new FirebirdSql.Data.FirebirdClient.FbDataAdapter("select
first 3 LastName from Student", conn);

         // Uncomment this line to demonstrate that columns created
*before* Fill work as expected.
         //coeStudTable.Columns.Add("LastName", typeof(string));

         adapter.Fill(coeStudTable);

         // These lines demonstrate that columns created *after* Fill
also work as expected.
         coeStudTable.Columns.Add("Foo", typeof(string));
         foreach (DataRow r in coeStudTable.Rows)
            r["Foo"]=r["LastName"];

         // These lines demonstrate that changes are making it from
the UI back to the DataColumn, but
         // notification is not making it back out to the UI.
         coeStudTable.ColumnChanging+=coeStud_ColumnChanging;
         coeStudTable.RowChanging+=coeStud_RowChanging;
      }

      void coeStud_RowChanging(object sender, DataRowChangeEventArgs e) {
         System.Diagnostics.Debug.WriteLine("RowChanging");
      }

      void coeStud_ColumnChanging(object sender, DataColumnChangeEventArgs e) {
         System.Diagnostics.Debug.WriteLine("ColumnChanging");
      }
   }
}

------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to