none
Bug in DataRowCollection.Contains and DataRowCollection.Find Methods? RRS feed

  • Question

  • Hi,

    There is a table called Servers in my database. I read it as follows:

    SELECT * FROM Servers

    This creates ADO.NET object called serversTable. I then try to establish existence of a row using DataRowCollection.Contains(stringId) method, but the call generates an exception which says that the table jas no primary key.

    When I check with SQL Server Management Studio, the table clearly HAS a primary key. Also, when I check the serversTable object (with the debugger), it also confirms existence of primary key: it is a varchar column named Name.

    I encounter the same problem with the DataRowCollection.Find method.

    It so happens the table is empty - but the SQL SELECT  call does read the table schema, and there is obvious evidence of primary key when I inspect the serversTable objct.

    What am I missing? Any workarounds? Any ideas would be greately appreciated.

    Thanks,

    Peter Battelino


    PMBT
    Wednesday, December 1, 2010 5:48 PM

Answers

All replies

  • Hi Peter,

    Could you please show me what code you are using to fill the DataTable?

    We only load the Schema information for the Primary Key if you set the MissingSchemaAction to AddWithKey, or if you call FillSchema before filling the DataTable.

    Thanks,
    Daniel

    • Marked as answer by liurong luo Wednesday, December 8, 2010 11:04 AM
    Wednesday, December 1, 2010 9:55 PM
  • Daniel,

    Thank you so much for your reply, and my apologies for my very late response - I was side-tracked to another project on emergency basis.

    I use DataAdapter Fill method, and - you are correct, setting MissingSchemaAction to AddWithKey solves the problem.

    Best regards,

    Peter Battelino


    PMBT
    Thursday, December 9, 2010 10:58 PM