none
C# Script Task - MessageBox Variables

    Question

  • I dont know C#, so I thought I would start simple and try to do message box a variable. I am struggling even with that.

     

    In VB.net I would print a value of the variable in a message box using the following syntax.

     

                    Msgbox(dts.variables(“VariableName”).value.tostring)

     

    In C#

                    MessageBox.Show(Dts.Variables

     

    At the point of selecting variables it is giving me this message.

                    Error      1              Non-invocable member 'Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTAProxy.ScriptObjectModel.Variables' cannot be used like a method.         

     

    I have following using statements defined. Do I need more?

                    using System;

    using System.Data;

    using Microsoft.SqlServer.Dts.Runtime.VSTAProxy;

    using System.Windows.Forms;

    using Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTAProxy;


    I might be missing something. Can anyone help?

     

    Thanks

    Sutha

    Friday, July 11, 2008 10:59 AM

Answers

  • Indexing is done differently in C#.  To get the string representation of a variable called Foo, you would use:
    Dts.Variables["Foo"].Value.ToString()
    (notice the []s instead of ()s)

    Hence, to display a message box, you'd place that into the Show() call:
    MessageBox.Show(
    Dts.Variables["Foo"].Value.ToString())
    Friday, July 11, 2008 5:09 PM

All replies

  • Indexing is done differently in C#.  To get the string representation of a variable called Foo, you would use:
    Dts.Variables["Foo"].Value.ToString()
    (notice the []s instead of ()s)

    Hence, to display a message box, you'd place that into the Show() call:
    MessageBox.Show(
    Dts.Variables["Foo"].Value.ToString())
    Friday, July 11, 2008 5:09 PM
  • Brandon

     

    Thank you.

     

    Sutha

    Saturday, July 12, 2008 12:59 PM
  • Why do I get the following exception?:

    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

    Wednesday, June 25, 2014 5:41 PM
  • Before using variables in your script (i.e. before clicking on 'Edit Script...' button), select variables to be used in your script in 'ReadOnlyVariables' or in 'ReadWriteVariables'.

    Script Task variables


    G. Mustafa

    Thursday, October 01, 2015 4:07 PM