locked
Reading Data from MS Access using Microsoft.Jet.OLEDB.4.0, Does not start reading data from First row of the physical table RRS feed

  • Question

  • Hi

    I'm having MS Access database and using Microsoft.Jet.OLEDB.4.0 provider in Data Driven Unit Test.

    [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|\\AccessDatabase\\TestDb.mdb", "TableName", DataAccessMethod.Sequential), DeploymentItem("FolderName\\AccessDatabase\\TestDb.mdb"), TestMethod]

    Then getting data from <TableName> row by row

    TestContext.DataRow["ColumnName1"].ToString()

    But the problem is it reads the row in randow order.. say row 20th first then read row 5th then some other row. However, I want to read the row in the same order in which is there physically showing up in database.

    I would appreciate, if somebody help me out ?


    • Edited by Ahsan Mumtaz Wednesday, September 10, 2014 1:46 AM
    • Moved by Caillen Wednesday, September 10, 2014 6:38 AM
    Tuesday, September 9, 2014 8:53 PM

Answers

  • The issue is finally resolved. The data is getting read from the table in the same order in whichi it's been inserted, even if we maintain them differently i.e. sort or arrange the rows per the needs.  

    I simply create a View of the table i.e. SELECT * FROM <TableName> Order By TestCaseId

    and use the view name in data source instead of table name, in that way the data always read order by TestCaseId.

    Thanks

    Ahsan


    • Marked as answer by Ahsan Mumtaz Wednesday, September 17, 2014 12:19 PM
    • Edited by Ahsan Mumtaz Thursday, September 18, 2014 3:45 PM
    Wednesday, September 17, 2014 12:19 PM

All replies

  • Hi Ahsan,

    Unit Testing forum is the most suitable place for your question, I'm helping you to move it here.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 10, 2014 6:40 AM
  • Hi Ahsan,

    >>But the problem is it reads the row in randow order.. say row 20th first then read row 5th then some other row. However, I want to read the row in the same order in which is there physically showing up in database.

    Could you share me a screen shot about the above result in your side?

    >>DataAccessMethod.Sequential

    As far as as I know, if we use this method, the Rows are returned in a sequential order. It is different from "Random" method.

    So Please check whether it is your database issue.

    This is a simple sample:

    http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.dataaccessmethod.aspx

    If you run your test in VS2013, you could get the detailed test result with the rows in Test Explorer window.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.


    Thursday, September 11, 2014 4:48 AM
  • The issue is finally resolved. The data is getting read from the table in the same order in whichi it's been inserted, even if we maintain them differently i.e. sort or arrange the rows per the needs.  

    I simply create a View of the table i.e. SELECT * FROM <TableName> Order By TestCaseId

    and use the view name in data source instead of table name, in that way the data always read order by TestCaseId.

    Thanks

    Ahsan


    • Marked as answer by Ahsan Mumtaz Wednesday, September 17, 2014 12:19 PM
    • Edited by Ahsan Mumtaz Thursday, September 18, 2014 3:45 PM
    Wednesday, September 17, 2014 12:19 PM