[IronPython] DataRows and IronPython 2.0 B3

Michael Foord fuzzyman at voidspace.org.uk
Mon Jun 23 08:30:21 PDT 2008


Note that we can fix it by iterating over 'row.ItemArray' instead, I 
just wondered if the breakage was intentional.

Michael Foord

Michael Foord wrote:
> Hello all,
>
> I'm further investigating potential compatibility issues with moving 
> Resolver One to IronPython 2, and I've encountered a change in 
> behaviour with respect to iterating over DataRows.
>
> The script below works in IronPython 1, printing all the data in the 
> rows. In IronPython 2.0 B3 it raises an exception.
>
> IronPython 1:
> C:\compile>c:\Binaries\ironpython\ipy.exe test_data.py
> 0 System.Data.DataRow
>     0 A Big Boy Did It and Ran Away
> 1 System.Data.DataRow
>     0 Affective Computing
> 2 System.Data.DataRow
>     0 Clear and Present Danger
>
> IronPython 2:
> C:\compile>c:\Binaries\ironpython2\ipy.exe test_data.py
> 0 <System.Data.DataRow object at 0x000000000000002B 
> [System.Data.DataRow]>
> Traceback (most recent call last):
>  File "test_data.py", line 29, in test_data.py
> TypeError: expected IEnumerator, got DataRow
>
>
> Test script:
>
> import clr
> clr.AddReference('System.Data')
>
> from System.Data import DataSet
> from System.Data.Odbc import OdbcConnection, OdbcDataAdapter
>
>
> connectString = (
>    "DRIVER={MySQL ODBC 3.51 Driver};"
>   "blah blah blah"
>    "OPTION=3;"
> )
>
> query = "SELECT title FROM books WHERE price > 2 ORDER BY title"
>
> connection = OdbcConnection(connectString)
> adaptor = OdbcDataAdapter(query, connection)
> dataSet = DataSet()
> connection.Open()
> adaptor.Fill(dataSet)
> connection.Close()
>
> for rowIndex, row in enumerate(dataSet.Tables[0].Rows):
>    print rowIndex, row
>    for colIndex, data in enumerate(row):
>        print '    ', colIndex, data
>
> Michael Foord
> http://www.ironpythoninaction.com/
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Users mailing list