DataAdapter Fill/Get retrieves wrong rows RRS feed

  • Question

  • Hello, I am having difficulty with DataAdapter retrieving totally wrong rows with Get/Fill methods which result in ConstraintException. I use same DataAdapter and same Fill method couple of times before RTE without any problems, but at third time it looks like Fill method uses wrong sql clause and retrieves rows from wrong table. When I open ItemArray of the retrieved row I can see it does not belong to this DataTable at all. When I call different Get methods of DataAdapters in Watch window, method always retrieves data which should be retrieved by previous method call. I mean the results come one step behind. If I pass this section same ConstaintException appears on next place where other DataAdapter Fill method is called and same situation continues. DataAdapters keep retrieving data one step behind. Any suggestions? Thanks in advance.


    PS. I use framework 4 and strongly typed datasets. Anyone have any idea?


    • Edited by Heli Hakala Tuesday, January 24, 2012 12:31 PM
    Tuesday, January 24, 2012 8:43 AM

All replies

  • Hi Heli Hakala,

    Welcome to MSDN Forum.

    Based on the issue, I think you'd better post the code here. This is, so I can help you more effectively.

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, January 25, 2012 6:39 AM
  • This snapshot shows the first time this code is called and where ItemArray of the first retrieved row is correct. FillByIc method contains sql clause "SELECT Id, Name, Value FROM ICCalculationParameters WHERE (Id = @id)". _icid is in this case 444 and all retrieved rows have this id on the first column. 

    The next snapshot shows the situation after third time the code is called and where error appears. ItemArray of the first retrieved row is object[23] not object[3] as it should be. And the content of it actually is from other table, not from ICCalculationParameters. So there happens to be dbnull in place of the Name column and ConstraintException appears.

    (This forum has two images per message limit so I continue the case in another message...)




    Wednesday, January 25, 2012 7:08 AM
  • Then if I try to get all rows from ICCalculationParameters table in Watch window with "_parameterAdapter.GetData()" and open results in DataSet Visualizer there is only rows with id 549 which was the id in previous case above (there select was limited with _icid = 549). 

    And when I execute "_parameterAdapter.GetDataByIc(1)" after that I get all rows from the table.

    So it seems that DataAdapter retrieves data one step behind. And this situation continues in spite of DataAdapter. If I use any other DataAdapter it retrieves data which should have been retrieved in previous case. 

    So what can cause this mess? And what I can do to fix it?

    Wednesday, January 25, 2012 7:31 AM
  • What does the .FillByIc() method look like? It seems like something is not quite right in that method. And where does it come from? You said you're using a DataAdapter, but that sounds like either a generated TableAdapter or your own code.
    ~~Bonnie Berent [C# MVP]
    Sunday, January 29, 2012 5:44 AM
  • Hi Heli Hakala,

    Sorry for late response, I have just ended my holiday.

    I agree with Bonnie, could you please post the code here?

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, February 2, 2012 5:42 AM