0

Possible Duplicate:
C# eval equivalent?

how can i execute A command from some string on windows forms application like this:

string s=" MessageBox.Show(\"Hello World !\"); "
//and then execute s like a dynamic string in sql
//execute(s)

//does it mean that there is no command that executes string in c#?

Community
  • 1
  • 1
Mohsen
  • 3,670
  • 7
  • 37
  • 68
  • 1
    Wait, what who how? execute a messageBox.Show in sql... Thats the real challenge. – Polity May 17 '11 at 11:32
  • I've seen it done before, but that was a class that was compiled at runtime and called via reflection. C# is compiled to IL so this is not as simple as an interpreted language. (this is a good thing) – Jodrell May 17 '11 at 11:34
  • @Polity: I think that he means in the same manner as `execute` in SQL, but for C#. – Guffa May 17 '11 at 11:34
  • Your question is a bit vague. Do you want to have an input field, where you can enter an SQL-query an execute it? – Serkan May 17 '11 at 11:34
  • I have to disagree about being a duplicate of "C# eval equivalent?". This question is about how to execute SQL that was entered by the user. – Martin Liversage May 17 '11 at 11:36
  • @Polity, Serkahn: I believe Moshen would like to execute the string `s` in C# as if it were a statement. This is similar to an approach called Dynamic SQL in TSQL. – Jodrell May 17 '11 at 11:37
  • @Martin: nonsense. Do you see any SQL in his sample code? I don't. He wants to execute C# code. – Daniel Hilgarth May 17 '11 at 11:45
  • @Daniel Hilgarth: I interpret _and then execute s like a dynamic string in sql_ that this is about dynamic SQL but maybe my interpretation is wrong? – Martin Liversage May 17 '11 at 12:02
  • @Martin: Having a look at the content of `s` should make it completely clear that your interpretation is wrong and he wants to dynamically execute C# code *like it can be done in SQL* (or JavaScript, ...) – Daniel Hilgarth May 17 '11 at 12:04
  • i mean same manner as execute in SQL, but for C# – Mohsen May 18 '11 at 09:11
  • @Martin:i want to dynamically call c# code witch i made it to a string – Mohsen May 18 '11 at 12:31

0 Answers0