Executing command/instruction from a string variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gancy

    #1

    Executing command/instruction from a string variable

    I need to execute the command/instruction which is stored in a
    variable. ex

    string str = "drRow["userid"].ToString()"

    here i need execute the instruction stored in 'str' and get the value
    from executing

    drGalileoToday["userid"].ToString()

    I have no idea as how this could be done. Please advise
  • Marc Gravell

    #2
    Re: Executing command/instruction from a string variable

    c# is not an interpreted language like javascript etc, so there is no easy
    way to do this. In some cases you can use the compiler directly, but this is
    not usually appropriate and there are security issues (that string could be
    anything) - and scoping issues (how to supply drRow to an arbitrary block of
    code).

    In short - I don't think that this is the right approach to start with.
    There may be more suitable approaches if you can tell us *why* you want to
    do this. For example, if you just new "userid" and wanted to get the string
    contents, then it would be trivial...

    Marc


    Comment

    • Peter Duniho

      #3
      Re: Executing command/instruction from a string variable

      On Thu, 27 Mar 2008 02:50:01 -0700, Gancy <gancy26@gmail. comwrote:
      sorry for multi posting. I wasn't sure if post was appropriate on
      framework or language.
      It was nominally related to either. The problem is that you posted your
      message twice, rather than cross-posting (which is different from
      multi-posting, what you did) it once to two different newsgroups. That
      made it impossible for Jon to know, reading the framework newsgroup, that
      the question had already been answered here in the C# newsgroup.

      Pete

      Comment

      Working...