Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Executing command/instruction from a string variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gancy - 27 Mar 2008 10:24 GMT
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 - 27 Mar 2008 10:31 GMT
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
Jon Skeet [C# MVP] - 27 Mar 2008 10:42 GMT
<snip>

> I have no idea as how this could be done.  Please advise

Please don't multi-post. I wouldn't have answered the question in the
framework group if I'd seen that Marc had already provided a perfectly
good answer here.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Gancy - 27 Mar 2008 10:50 GMT
> <snip>
>
[quoted text clipped - 7 lines]
> Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk

sorry for multi posting.  I wasn't sure if post was appropriate on
framework or language.
Peter Duniho - 27 Mar 2008 16:23 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.