locked
Can TestContext.DataRow be used to write to the datasource? RRS feed

  • Question

  • I've been using TextContext.DataRow["ColumnName"].ToString() to grab data from a spreadsheet to drive my tests.

    (I had to wrap the excel spreadsheet in ODBC to get it working but maybe that could be the subject of another post.)

    My question today is can I use TextContext.DataRow to write to the spreadsheet. Perhaps:

    TextContext.DataRow["TestResult"] = "passed";

    But that does not work.

     

    Then I noticed Datarow has interesting methods like BeginEdit, EndEdit so I tried:

     

    TestContext.DataRow.BeginEdit();
    TestContext.DataRow["updateme"] = "updated";
    TestContext.DataRow.EndEdit();
    TestContext.DataRow.AcceptChanges();

    But that doesn't work either.

    Am I going to have to use the interop library?

     

    Thanks

     

    Mike

    • Edited by sovande Monday, March 22, 2010 12:17 PM layout
    • Moved by Mathew Aniyan MSFT Wednesday, March 24, 2010 4:36 AM Question for unit testing framework (From:Visual Studio UI Automation Testing (includes CodedUI))
    Monday, March 22, 2010 12:15 PM

All replies

  • What is the pupose you are trying to achieve. Changing the data set from a test which is itself driven by the same data set, does not seem to be a valid use case.
    Tuesday, March 23, 2010 6:04 AM
  • Your question: "What is the pupose you are trying to achieve?"

    OK, I didn't explicitly state the purpose but the clue was in this line:

    TextContext.DataRow["TestResult"] = "passed";

     

    I know the system writes test results to the test results folder, but I've been asked by our test team if it would be possible to update the datasource spreadsheet to indicate that a test passed or failed.

    The columns in the datasource spreadsheet would look something like:

    testID, senario, result , col1_data, col2_data, col3_data, etc

     

    So my question remains: Can TestContext.DataRow be used to update the datasource?

    Thanks

    Mike
    Tuesday, March 23, 2010 9:17 AM
  • Any chance of an answer?
    Monday, April 5, 2010 9:12 PM
  • Although I've never seen this attempted, it may be possible.  Since you can get to the underlying DataSet via "TestContext.DataRow.Table.DataSet".  It may be possible to setup an OleDbAdapter to then update the spreadsheet appropriately.

    It could be that the spreadsheet is open in a "read only" mode (of some sort) that would prevent writing back to it.  I have no idea as to whether this would work but it might be worth checking into.

    Hope this helps.


    --- Thanks, Jeff (http://devmatter.blogspot.com/)
    Thursday, April 8, 2010 1:09 PM
  • System.Data.Common.DbCommand cmd = TestContext.DataConnection.CreateCommand(); cmd.CommandText = string.Format("INSERT INTO [{0}] ({1}) VALUES ('{2}')", SheetName, column, value); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery();


    Create a command object using the TestContext's connection to the datasource and use this to write/update.

    • Edited by bn0 Monday, December 17, 2012 7:54 PM
    Monday, December 17, 2012 7:52 PM
  • Hi,

    I tried the above solution (Proposed by bn0) but it does not work. Code executes without any error but also does not update the Excel sheet .. any idea?

    Regards,

    SJ

    Wednesday, November 6, 2013 11:05 AM