Slavich
(Slava)
January 15, 2020, 9:09am
1
Hi Guys,
I faced the issue while using invoke C# code.
I receive an Error:
while trying to invoke this code:
for (int i = 20; i < inputDt.Rows.Count; i++)
{
for (int j = 1; j < inputDt.Columns.Count; j++)
{
if (!String.IsNullOrEmpty(inputDt.Rows[i][j].toString()) && inputDt.Rows[i][j] != “0”)
{
System.Data.DataRow dr = null;
dr = outputDt.NewRow();
dr[0] = inputDt.Rows[0][j];
dr[1] = inputDt.Rows[1][j];
dr[2] = inputDt.Rows[i][0];
dr[5] = inputDt.Rows[i][j];
outputDt.Rows.Add(dr);
}
}
}
The list of arguments is:
Any idea why it causes and how can be resolved?
Thanks
Slavich
(Slava)
January 15, 2020, 9:53am
2
Solved:
instead of !String.IsNullOrEmpty(inputDt.Rows[i][j].toString()
made inputDt.Rows[i][j]!=DBNull.Value
1 Like
Slavich
(Slava)
January 15, 2020, 1:58pm
3
Ultimately, I don’t receive and error. But i get wrong results. So I need compare the cell values as a String.
Why Invoke code doesn’t work with .toString ??? Anyone knows?
Try doing this -
Create your own new string ad hoc in the loop this way -
YourString=inputDt.Rows[i][j];
string.isnullorempty(YourString);
Normally C# the type conversion of ToString should always be followed by “()” it is very strict about that.
1 Like
Slavich
(Slava)
January 15, 2020, 2:39pm
5
Do u mean escape from using Invoke and to do everything in ad hoc loops?
Well TBH I have faced issues when using C# code in invoke code, either go with VB or you can use the inbuilt loops for this purpose. It will be more readable for people who are maintaining your code.
1 Like
Slavich
(Slava)
January 15, 2020, 2:58pm
7
Once I tried
i received : cannot convert object ot string.
Then I added inputDt.Rows[i][j].toString - and received “cannot implicitly convert object to string”.
So you are right. Other way to do this should be made up. Invoke code activity is not good enough if doesnt work with toString…