• grappling with common programming problem (.NET framework 1.1)

    Home » Forums » Developers, developers, developers » DevOps Lounge » grappling with common programming problem (.NET framework 1.1)

    Author
    Topic
    #413045

    Hi Loungers,
    I have this line of code which works:

    this.clientDS.Tables[“Contacts”].ImportRow(row);

    I have a lot of tables where I want to import a row, so I just want to pass a table into a method, like so:

    private void CopyDataTable(DataTable dataTable)
    {
    some code here
    this.calloutDS.Tables(dataTable.TableName.ToString()).ImportRow(row);
    }
    any suggestions greatly appreciated.

    Viewing 1 reply thread
    Author
    Replies
    • #908253

      I missed the question… Does your code not work? Or are you just looking for best-practice suggestions?

      • #908301

        Hi Mark – duh! I forgot to say that this line generates an error.

        this.calloutDS.Tables(dataTable.TableName.ToString()).ImportRow(row);

        I get a compile-time error message which is incomprehensible to me: “Cannot apply indexing with [] to an expression of type ‘System.Data.Dataset’.
        It works fine if I substitute a literal in quotes, e.g.

        this.calloutDS.Tables(“Persons”).ImportRow(row);

        But then I’d have to write a separate little routine for each table … barf

        • #908389

          Try square brackets for the Table reference:

          this.calloutDS.Tables[dataTable.TableName.ToString()].ImportRow(row);

          If that doesn’t work, try assigning the table name to a string variable then using the syntax above.

          Hope this helps smile

          • #908560

            I’m so happy I could jump for joy! Thank you – the square brackets worked! I’m so used to VBA that I never think of square brackets.

            Mark – do you have any words of wisdom about when to use square brackets?

            coffeetime

            • #908572

              Switch to VB.Net and avoid them entirely?? innocent duck

            • #910978

              Yes, C# is more difficult to use with Office than VB .NET.

              Hopefully, this difference will go away when Office is filly .NET-ized.
              Until then, I’m sticking with VB .NOT.

            • #910979

              Yes, C# is more difficult to use with Office than VB .NET.

              Hopefully, this difference will go away when Office is filly .NET-ized.
              Until then, I’m sticking with VB .NOT.

            • #908573

              Switch to VB.Net and avoid them entirely?? innocent duck

            • #908970

              Here’s the helpfile contents for the [] operator, from Mcirosoft: operator.asp”]http://msdn.microsoft.com/library/default….sref/html/vclrf[]operator.asp[/url].

              To expand on Charlotte’s post… I was curious why you’re using C# since I think I remember that your background is mostly in the VB/VBA world? I used VB.NET exclusively until this year, when I discovered the inline documentation capabilities of C# (which will be added to VB.NET 2.0). However, I took a new job about 6 weeks ago that exclusively uses C# so I’ve learned to work with both. If someone were learning to program with no prior experience (or experience with C, C++ or Java), I would recommend C#. But for anyone who has experience with VB/VBA, I would definitely recommend VB.NET.

            • #909378

              Hi Mark and Charlotte,
              I agree with you and like you am learning C# because my work demands it. I’m reading “Visual C#.Net : A guide for VB6 Developers”. Wrox Press. I’m finding it very useful. I miss VB’s case insensitivity. In the Wrox book it says, “Microsoft has developed this new langugage taking the best of many languages, making it easy and powerful, and has even used it to write the FCL. Microsoft is pushing to make C# the lead language for .NET programming.”

              I’m having to learn so many new concepts: inheritance, polymorphism, constructors and destructors and namespaces, overloading, free threading, delegation – and these are all in VB.NET and C#.NET, so it doesn’t seem a big burden to also learn a new, more elegant language, which takes the best of java and VB and other languagues.

              “in for a penny; in for a pound” …whatever that means
              compute

            • #909695

              [indent]


              “in for a penny; in for a pound” …whatever that means


              [/indent] It means you’ve been hanging out with the Brits in the Lounge too much! laugh

            • #909696

              [indent]


              “in for a penny; in for a pound” …whatever that means


              [/indent] It means you’ve been hanging out with the Brits in the Lounge too much! laugh

            • #910662

              I’m finding that the autocomplete (Control +space) plus naming standards can help towards case sensitivity. I was dreading it after earlier experience with C++ but I’m not finding it a big issue.

            • #910743

              I recently discovered Ctrl + J for C#…. Works wonders!!

            • #910744

              I recently discovered Ctrl + J for C#…. Works wonders!!

            • #910663

              I’m finding that the autocomplete (Control +space) plus naming standards can help towards case sensitivity. I was dreading it after earlier experience with C++ but I’m not finding it a big issue.

            • #909379

              Hi Mark and Charlotte,
              I agree with you and like you am learning C# because my work demands it. I’m reading “Visual C#.Net : A guide for VB6 Developers”. Wrox Press. I’m finding it very useful. I miss VB’s case insensitivity. In the Wrox book it says, “Microsoft has developed this new langugage taking the best of many languages, making it easy and powerful, and has even used it to write the FCL. Microsoft is pushing to make C# the lead language for .NET programming.”

              I’m having to learn so many new concepts: inheritance, polymorphism, constructors and destructors and namespaces, overloading, free threading, delegation – and these are all in VB.NET and C#.NET, so it doesn’t seem a big burden to also learn a new, more elegant language, which takes the best of java and VB and other languagues.

              “in for a penny; in for a pound” …whatever that means
              compute

            • #908971

              Here’s the helpfile contents for the [] operator, from Mcirosoft: operator.asp”]http://msdn.microsoft.com/library/default….sref/html/vclrf[]operator.asp[/url].

              To expand on Charlotte’s post… I was curious why you’re using C# since I think I remember that your background is mostly in the VB/VBA world? I used VB.NET exclusively until this year, when I discovered the inline documentation capabilities of C# (which will be added to VB.NET 2.0). However, I took a new job about 6 weeks ago that exclusively uses C# so I’ve learned to work with both. If someone were learning to program with no prior experience (or experience with C, C++ or Java), I would recommend C#. But for anyone who has experience with VB/VBA, I would definitely recommend VB.NET.

          • #908561

            I’m so happy I could jump for joy! Thank you – the square brackets worked! I’m so used to VBA that I never think of square brackets.

            Mark – do you have any words of wisdom about when to use square brackets?

            coffeetime

        • #908390

          Try square brackets for the Table reference:

          this.calloutDS.Tables[dataTable.TableName.ToString()].ImportRow(row);

          If that doesn’t work, try assigning the table name to a string variable then using the syntax above.

          Hope this helps smile

    • #908254

      I missed the question… Does your code not work? Or are you just looking for best-practice suggestions?

    Viewing 1 reply thread
    Reply To: grappling with common programming problem (.NET framework 1.1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: