writexml method triggers show form
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: writexml method triggers show form

  1. #1
    Join Date
    Aug 2011
    Posts
    4

    writexml method triggers show form

    I think this is more general c# question than ado.net....

    Program worked ok, until I added method which puts this table in xml. I went debugging and on line marked program pops up my windows form and stops (waiting to trigger some event on that form by user (click button etc)). But Form shouldn't apear at this line in code. Why is this happening?
    I have just started to learn c# and I'm new to visual studio 2010 (using it on win7 64 bit).Please some advice, maybe it is more about some VS 2010 setup that i'm not aware of.th
    Without this newly added line everything is working as expected...


    private DataTable BuildSampleTable()
    {
    // ------ Create a sample table to display in the application.
    DataTable theTable = new DataTable("SampleTable");
    theTable.Columns.Add("ID", typeof(long));
    theTable.Columns.Add("StudentName", typeof(string));
    theTable.Columns.Add("GradeYear", typeof(int));
    theTable.Columns.Add("ScoreTrimester1", typeof(decimal));
    theTable.Columns.Add("ScoreTrimester2", typeof(decimal));
    theTable.Columns.Add("ScoreTrimester3", typeof(decimal));

    // ----- Create a primary key for the table.
    theTable.PrimaryKey = new DataColumn[] {theTable.Columns["ID"]};

    theTable.Rows.Add(new Object[] {3429L, "Abercrombie, Kim", 12, 4m, 3.9m, 4m});
    theTable.Rows.Add(new Object[] {2352L, "Hamlin, Jay", 10, 2.5m, 1.85m, 1.7m});
    theTable.Rows.Add(new Object[] {6843L, "Jacobsen, Lola", 10, 2.67m, 2.9m, 3.2m});
    theTable.Rows.Add(new Object[] {4810L, "Price, Jeff", 11, 3m, 3m, 3.4m});

    theTable.WriteXml(@"c:\mydoc.xml"); // <-------------------------------------------------

    return theTable;
    }

  2. #2
    Join Date
    Aug 2011
    Posts
    4

    Re: writexml method triggers show form

    same thing is with following code from some other program:

    private DataTable BuildParentTable()
    {
    // ----- Create a sample parent table.
    DataTable result;
    DataColumn keyColumn;

    // ----- Design the table structure.
    result = new DataTable("Customer");
    keyColumn = result.Columns.Add("ID", typeof(int));
    result.Columns.Add("BusinessName", typeof(string));
    result.Columns.Add("AnnualFee", typeof(decimal));
    result.Columns.Add("ContractDate", typeof(DateTime));
    result.PrimaryKey = new DataColumn[] {keyColumn};

    // ----- Add some sample data.
    result.Rows.Add(new Object[] {1, "City Power & Light",
    500m, DateTime.Parse("6/1/2008")});
    result.Rows.Add(new Object[] {2, "Lucerne Publishing",
    300m, DateTime.Parse("1/1/2008")});
    result.Rows.Add(new Object[] {3, "Southridge Video", // <--------------- windows form pops up
    350m, DateTime.Parse("2/15/2010")});

    return result;
    }
    it is really strange to me how can some code trigger show form, maybe it is better that i attach whole solution (it is from step by step vs 2010 from microsoft press)
    Attached Files Attached Files

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,201

    Re: writexml method triggers show form

    When the Form pops up, what does it say?

  4. #4
    Join Date
    Aug 2011
    Posts
    4

    Re: writexml method triggers show form

    nothing, as it was called with Form.Showdialog. It is just there, program stops and waiting to trigger some event. I have posted another post with complete solution from another program but moderator need to confirm it. It is same thing but form pops up when i'm bulding a table, pop up goes on table.rows.add(.....) method.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,201

    Re: writexml method triggers show form

    Quote Originally Posted by mata123 View Post
    nothing, as it was called with Form.Showdialog. It is just there, program stops and waiting to trigger some event.
    Well, don't call that if you don't want the form to appear.

    Quote Originally Posted by mata123 View Post
    I have posted another post with complete solution from another program but moderator need to confirm it. It is same thing but form pops up when i'm bulding a table, pop up goes on table.rows.add(.....) method.
    I'm a mod and I don't see any other posting from you. I downloaded your program and it starts up for me without any additional popups. I hit the 'generate' button and the program seems to generate xml. Are there other repro steps that I need to try?

  6. #6
    Join Date
    Aug 2011
    Posts
    4

    Re: writexml method triggers show form

    by help of experts i did try catch routing

    and...oh my God, it seems this is an american version of code, and DateTime is in mm/dd/yyyy format, i guess on american computers (time setup) it works ok, I had to put all dates in dd/mm/yyyy format (chapter 7 solution)
    try catch block discovered the problem, I didn't know that error could happened with no warning, I expect always at least that program crashes


    for writexml problem... my program didn't have rights to write to root

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,201

    Re: writexml method triggers show form

    So the form turned out to be an exception dialog thrown by the .Net framework?

    That's why I asked you what was on the form earlier.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center