Groups | Blog | Home
all groups > dotnet windows forms databinding > october 2004 >

dotnet windows forms databinding : Column must belong to a table?


Paschalis Pagonidis
10/21/2004 1:28:03 AM
Hi to all,

I get this ArgumentException just when:
((System.ComponentModel.ISupportInitialize)
(this.dataTable2)).EndInit();

runs inside InitializeComponent()...

It raises when I set primary key on the table:

The code I use is:
this.dataTable2.Columns.AddRange(new System.Data.DataColumn
[] {this.dataColumn3, this.dataColumn4});

this.dataTable2.Constraints.AddRange(new
System.Data.Constraint[] {
new System.Data.UniqueConstraint("Constraint1", new
string[] {"dm_dpt_id", "dm_mod_id"}, true)});

this.dataTable2.PrimaryKey = new System.Data.DataColumn[] {
this.dataColumn3, this.dataColumn4};

this.dataTable2.TableName = "dm";

this.dataColumn3.AllowDBNull = false;
this.dataColumn3.ColumnName = "dm_dpt_id";
this.dataColumn3.DataType = typeof(int);

this.dataColumn4.AllowDBNull = false;
this.dataColumn4.ColumnName = "dm_mod_id";
this.dataColumn4.DataType = typeof(int);

Table dm:
+---------------------+
| dm |
+---------------------+
| PK int(4) dm_dpt_id |
| PK int(4) dm_mod_id |
ScaveMail NO[at]SPAM gmail.com
10/21/2004 5:36:40 PM
Hi,

I just tried out the following test example and no exceptions were
thrown:
DataTable table1 = new DataTable();
DataColumn[] primaryKeyCols = new DataColumn[] {new
DataColumn("Col 1"), new DataColumn("Col 2")};
table1.Columns.AddRange(primaryKeyCols);
table1.PrimaryKey = primaryKeyCols;

The result is a DataTable with one Unique Constraint between "Col 1"
and "Col 2" which is also the primary key.
Is there something I'm failing to do that your code requires?


[quoted text, click to view]
Paschalis Pagonidis
10/22/2004 1:25:06 AM
Hmm, the concept is the same. You create two fields,
assign them to table1 and make them primary keys.

There is something that causes the compiler to "complain".
For the moment I removed the constraint and I manage it by
hand, until I finish with the remaining code...

Thanks anyway...

[quoted text, click to view]
AddThis Social Bookmark Button