[IronPython] Re: Working with System.Data.DataColumn[]

Martin Maly martmaly at exchange.microsoft.com
Wed Apr 20 03:24:47 CEST 2005


Anthony,

Yes, there is a way. With few changes your code is essentially correct:

import sys
sys.LoadAssemblyByName('System.Data')
from System      import Type, Console, Array
from System.Data import DataSet, DataColumn
key = Array.CreateInstance(DataColumn, 1)
dataset = DataSet('MySet')
dataset.Tables.Add('Order')
dataset.Tables['Order'].Columns.Add('OrderID',
Type.GetType('System.Int32'))
dataset.Tables['Order'].Columns.Add('CustomerFirstName',
Type.GetType('System.String'))
dataset.Tables['Order'].Columns.Add('CustomerLastName',
Type.GetType('System.String'))
dataset.Tables['Order'].PrimaryKey
dataset.Tables['Order'].Columns['OrderID']
key[0] = dataset.Tables['Order'].Columns['OrderID']
dataset.Tables['Order'].PrimaryKey = key


The PrimaryKey property is property of type "DataColumn[]" which
suggests that you should be
able to index it, but upon creation the array is that of length 0. The
primary key array
needs to be created separately:

key = Array.CreateInstance(DataColumn, 1)
key[0] = dataset.Tables['Order'].Columns['OrderID']
dataset.Tables['Order'].PrimaryKey = key

and then things work.

Martin

>>> Anthony Tarlano Wrote:
>>> To all:
>>> Is there anyway to add a System.Data.DataColumn instance to the
>>> PrimaryKey System.Data.DataColumn[] in IronPython??









More information about the Ironpython-users mailing list