-
September 17th, 2014, 08:55 AM
#1
... 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;
}
-
September 17th, 2014, 01:35 PM
#2
Re: ... is a variable but used like a method
Did you mean to pass arow an indexer instead of a parameter?
-
September 17th, 2014, 02:32 PM
#3
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";
-
September 19th, 2014, 01:32 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|