none
access an table from an object RRS feed

  • Question

  • Hi!

    I need form an object the rows and colums:

    How can I access the object?
    How can I fill the fields
    GrSpalte01 --> SuchNummer1(0)
    GrSpalte02 --> SuchNummer2(0)
    GrSpalte03 --> SuchText1(0)
    ...
    GrSpalte01 --> SuchNummer1(1)
    GrSpalte02 --> SuchNummer2(1)
    GrSpalte03 --> SuchText1(1)
    ...

    Have anyone an Idea or a Hint for me?

    Best Regards

    Bernd

    Monday, January 28, 2013 4:53 PM

Answers

  • This is ok:

    Array ar = (Array)MyTabelle;

    But he did not understand this:

    StandardSuchTabelle table = (WPFStandardSuchTabelle)ar[0];

    Error means:

    StandardSuchTabelle and WPFStandardSuchTabelle

    --> can not find...

    Best Regards

    Bernd
    • Marked as answer by Bernd Riemke Wednesday, January 30, 2013 2:38 PM
    Wednesday, January 30, 2013 7:31 AM

All replies

  • Have no one an idea?

    Best Regards

    Bernd

    Monday, January 28, 2013 7:09 PM
  • It looks like it should just be:  GrSpalte01 = MyTabelle[SBi].SuchNummer1; or GrSpalte01 = MyTabelle.Rows[SBi].Item["SuchNummer1"];


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, January 28, 2013 7:49 PM
    Moderator
  • The little problem is:

    publicObjectMyTabelle;

            public Object MyTabelle;

    In this object is the Table inside....
    Monday, January 28, 2013 7:51 PM
  • Why is it declared as Object instead of DataTable or a strongly-typed DataTable type?

    If it must be declared as object for some reason then you can cast it when reading the value:

    System.Data.DataTable table = (System.Data.DataTable)MyTabelle;
    GrSpalte01 = table.Rows[SBi].Item["SuchNummer1"];
    

    But it would be best to declare MyTabelle as a DataTable if that's the type the variable is going to hold.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, January 28, 2013 7:56 PM
    Moderator
  • If i use this:

                System.Data.DataTable table = (System.Data.DataTable)MyTabelle;
    The focus will go on to the WPF Mask before i can do something...

    and

    GrSpalte01 = table.Rows[SBi].Item["SuchNummer1"]
    on this line there is a problem with ".Item"


    Monday, January 28, 2013 8:08 PM
  • Can anyone help me please!?

    Best Regards

    Bernd

    Tuesday, January 29, 2013 8:22 AM
  • Rather than below

    GrSpalte01 = table.Rows[SBi].Item["SuchNummer1"]

    It should be

    GrSpalte01 = table.Rows[SBi]["SuchNummer1"]

    Let us know how it works

    Thanks, Durgesh Chaudhary. http://home.techphernalia.com

    Tuesday, January 29, 2013 9:40 AM
  • No, sorry..

    that will not be working...

    Because there is an error...

    He need an Assembly !?!?!

    Best Regards

    Bernd

    Tuesday, January 29, 2013 9:50 AM
  • He can not convert the object to a string...
    Tuesday, January 29, 2013 9:58 AM
  • Have anyone an idea for my problem?
    Tuesday, January 29, 2013 11:18 AM
  • Hi Bernd,

    Welcome to the MSDN Forum.

    Change it like this:

    GrSpalte01 = (string)table.Rows[SBi]["SuchNummer1"]

    It should be work.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 29, 2013 12:16 PM
    Moderator
  • I change the Code like this:

                System.Data.DataTable table = (System.Data.DataTable)MyTabelle;
                
                int SBi = 0;
                while (SBi < LVAnzahlInt32)
                {
    
                    GridList.Add(new WPFGridZeilen()
                    {
                        GrSpalte01 = (string)table.Rows[SBi]["SuchNummer1"],
                        GrSpalte02 = (string)table.Rows[SBi]["SuchNummer2"],
                        GrSpalte03 = (string)table.Rows[SBi]["SuchText1"],
                        GrSpalte04 = (string)table.Rows[SBi]["SuchText2"],
                        GrSpalte05 = (string)table.Rows[SBi]["SuchText3"],
                        GrSpalte06 = (string)table.Rows[SBi]["SuchText4"],
                        GrSpalte07 = (string)table.Rows[SBi]["SuchText5"],
    
                        //  GrSpalte01 = "a",
                        //  GrSpalte02 = "b",
                        //  GrSpalte03 = "c",
                        //  GrSpalte04 = "d",
                        //  GrSpalte05 = "e",
                        //  GrSpalte06 = "f",
                        //  GrSpalte07 = "g",
                    });
    
                    SBi++;
                }
    
                DataContext = GridList;
                
            }

    The Code is correct...

    But:

    If i use "GrSpalte01 = "a",....   (The Window will be show correct "a") and there is no System.Data.DataTable table = (System.Data.DataTable)MyTabelle;
    then the code will run correct!

    If i use the code on top with the line:
    System.Data.DataTable table = (System.Data.DataTable)MyTabelle;
    then the code is ending on this point ang go back to the window without going forward to the next line... (break...)

    What can i do that the code work correctly?

    Best Regards

    Bernd

    Tuesday, January 29, 2013 1:28 PM
  • If i work with "tra" and "catch" then i become an error:

    ... ca not convert object "WPFStandardSuchTabelle[]"  to  "System.Data.DataTable"...

    Something in the convert line is wrong...

    Thie line have a bug/mistake...

    System.Data.DataTable table = (System.Data.DataTable)MyTabelle;

    Best Regards

    Bernd

    Tuesday, January 29, 2013 1:46 PM
  • Have anyone an idea?

    Best Regards

    Bernd

    Tuesday, January 29, 2013 4:41 PM
  • Perhaps:

    System.Data.DataTable table= (System.Data.DataTable)MyTabelle[0];

    Is MyTabelle an array of DataTable objects then?  Or is it a DataSet maybe?

    Perhaps you should show us how MyTabelle gets its value...


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, January 29, 2013 9:22 PM
    Moderator
  • This will give me an error... -->System.Data.DataTable table=(System.Data.DataTable)MyTabelle[0];
    [0] is not allowd on an object...

    Here is the complete way:

    VB (Programm A):

    ... (ok) Public WPFSuchTabelle() As WPFStandardSuchTabelle ... (ok)
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=100)> Public SuchArray() As WPFStandardSuchTabelle ... (ok)
    <StructLayout(LayoutKind.Sequential)> Public Structure WPFStandardSuchTabelle <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=10)> Public SuchNummer1 As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=10)> Public SuchNummer2 As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText1 As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText2 As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText3 As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText4 As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText5 As String End Structure ...

    C# (Programm B)

    ...(ok) ?
    public Object Tabelle; ...(ok)
    Tabelle = MyVBDll.WPFSuchTabelle; ...(ok)
    ProblemWindow.MyTabelle = Tabelle;
    ...

    C# (Program C) here I must work with the object and the data from the VB program this ist the program with the little problem ...
    ...
            public Object MyTabelle;
    
    ... here is the mistake:
            System.Data.DataTable table = (System.Data.DataTable)MyTabelle;
    ...
    
    ... this ist now ok:
                        GrSpalte01 = (string)table .Rows[SBi]["SuchNummer1"],
                        GrSpalte02 = (string)table .Rows[SBi]["SuchNummer2"],
                        GrSpalte03 = (string)table .Rows[SBi]["SuchText1"],
                        GrSpalte04 = (string)table .Rows[SBi]["SuchText2"],
                        GrSpalte05 = (string)table .Rows[SBi]["SuchText3"],
                        GrSpalte06 = (string)table .Rows[SBi]["SuchText4"],
                        GrSpalte07 = (string)table .Rows[SBi]["SuchText5"],
    ...
    is this what you need !?

    Best Regards

    Bernd

    Tuesday, January 29, 2013 10:27 PM
  • OK I think I get it now, I thought WPFStandardSuchTabelle was a DataTable but it is its own structure.

    And MyTabelle appears to be an array of WPFStandardSuchTabelle.

    So then I guess it would just be:

    WPFStandardSuchTabelle table = (WPFStandardSuchTabelle)MyTabelle[0];

    -EDIT-

    Sorry I see the compiler doesn't like that... you need to cast MyTabelle as an array first... not sure the C# syntax on that...

    Sorry for misreading the screenshot... my C# is mediocre at best.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Tuesday, January 29, 2013 10:53 PM
    Moderator
  • Maybe:

    Array ar = (Array)MyTabelle;
    WPFStandardSuchTabelle table = (WPFStandardSuchTabelle)ar[0];


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, January 29, 2013 10:56 PM
    Moderator
  • This is ok:

    Array ar = (Array)MyTabelle;

    But he did not understand this:

    StandardSuchTabelle table = (WPFStandardSuchTabelle)ar[0];

    Error means:

    StandardSuchTabelle and WPFStandardSuchTabelle

    --> can not find...

    Best Regards

    Bernd
    • Marked as answer by Bernd Riemke Wednesday, January 30, 2013 2:38 PM
    Wednesday, January 30, 2013 7:31 AM