Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Variable is MyCounter type int32 and value 1.

Trying to write the script:

C#
public void Main()
{
    MessageBox.Show(Dts.Variables("MyCounter").Value);
Dts.TaskResult = (int)ScriptResults.Success;
}


I get the following error:
Non-invocable member 'Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.Variables' cannot be used like a method.

Need help
Thanks
Dov
Posted
Updated 2-Oct-15 18:38pm
v2

1 solution

In C#, you use square brackets [ ] for indexing; not parentheses.

C#
public void Main()
{
    MessageBox.Show(Dts.Variables["MyCounter"].Value);
Dts.TaskResult = (int)ScriptResults.Success;
}
 
Share this answer
 
Comments
Member 10311805 3-Oct-15 7:44am    
Hi,
I changed the script as suggested:

public void Main()
{
MessageBox.Show(Dts.Variables["MyCounter"].Value);
Dts.TaskResult = (int)ScriptResults.Success;
}
and after Build Solution I received 2 error messages::
Error 1 The best overloaded method match for 'System.Windows.Forms.MessageBox.Show(string)' has some invalid arguments and
Error 2 Argument 1: cannot convert from 'object' to 'string'

I am using here Microsoft Visual C#2010 does it make any difference?
can you please look into it?
PIEBALDconsult 3-Oct-15 11:21am    
Yes, I knew you would. The error messages tell you what you need to know.
Jaya Shanmuga Pandian 7-Oct-15 11:00am    
Add .ToString() at the end of Dts.Variables["MyCounter"].Value. That should work.
Kalyani Singh 16-Nov-20 11:07am    
This worked! Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900