CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2008
    Posts
    4

    ... is a variable but used like a method

    I am trying to iterate through a SQL Server result via SSIS C# Script task.
    I can't get past the line of code - sMsg = sMsg + acol.ColumnName + ": " + arow(acol.Ordinal).ToString + "\r\n";
    Getting "arrow is a variable but used like a method.

    Would someone be so kind and help me out?

    Thanks!

    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Runtime;
    using System.Windows.Forms;
    using System.Xml;
    using System.Data.OleDb;

    public void Main() {

    OleDbDataAdapter oleDA = new OleDbDataAdapter();
    DataTable dt = new DataTable();
    String sMsg = "";

    oleDA.Fill(dt, Dts.Variables["dsVarAltEmail"].Value);
    foreach (DataRow arow in dt.Rows) {
    foreach (DataColumn acol in dt.Columns) {
    sMsg = sMsg + acol.ColumnName + ": " + arow(acol.Ordinal).ToString + "\r\n";
    }
    MessageBox.Show(sMsg);
    sMsg = "";
    }

    Dts.TaskResult = (int)ScriptResults.Success;
    }

  2. #2
    Join Date
    Oct 2004
    Location
    Rocket City
    Posts
    220

    Re: ... is a variable but used like a method

    Did you mean to pass arow an indexer instead of a parameter?

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

    Re: ... is a variable but used like a method

    Please format your code with code tags

    Try
    Code:
    sMsg = sMsg + acol.ColumnName + ": " + arrow[acol.Ordinal].ToString + "\r\n";

  4. #4
    Join Date
    Apr 2014
    Location
    in northeast ohio
    Posts
    94

    Re: ... is a variable but used like a method

    something is obviously wrong with this line of code cause ToString() should look like that not ToString

    i don't think a Ordinal would belong in a indexer but without seeing more code i dunno
    my guess is that this is a method that returned a string with a ordinal sort of look to it
    acol.Ordinal() like 1 st 2nd 3 rd ect
    sMsg = sMsg + acol.ColumnName + ": " + acol.Ordinal().ToString() + "\r\n";
    or
    arow(acol).Ordinal().ToString(); // but then you really wouldn't need the to string in either case
    i would think this should work
    sMsg = sMsg + acol.ColumnName + ": " + arow.ToString() + "\r\n";

    http://stackoverflow.com/questions/2...-ordinals-in-c
    Last edited by willmotil; September 19th, 2014 at 01:41 PM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured