Click here to Skip to main content
15,893,508 members
Home / Discussions / C#
   

C#

 
AnswerRe: retrieve image from database help Pin
Richard MacCutchan16-Nov-13 0:53
mveRichard MacCutchan16-Nov-13 0:53 
GeneralRe: retrieve image from database help Pin
MichaelCheong8916-Nov-13 0:56
MichaelCheong8916-Nov-13 0:56 
SuggestionRe: retrieve image from database help Pin
Richard MacCutchan16-Nov-13 1:00
mveRichard MacCutchan16-Nov-13 1:00 
GeneralRe: retrieve image from database help Pin
MichaelCheong8916-Nov-13 1:47
MichaelCheong8916-Nov-13 1:47 
QuestionHow to execute c# statment in a string?(Compiling and Running code at runtime) Pin
jojoba201115-Nov-13 23:25
jojoba201115-Nov-13 23:25 
AnswerRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
Eddy Vluggen16-Nov-13 1:09
professionalEddy Vluggen16-Nov-13 1:09 
QuestionRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
jojoba201116-Nov-13 3:12
jojoba201116-Nov-13 3:12 
AnswerRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
Eddy Vluggen16-Nov-13 4:06
professionalEddy Vluggen16-Nov-13 4:06 
jojoba2011 wrote:
thanks but i get error.
 
Can u give me a small example!
If you'd get an error, it'd be more helpfull to solve that, than blindly trying examples.

I'm guessing that it's due to the fact that you only have the body of a method in there; just like in Visual Studio, the code needs to be located in a class. Try the example below in a console-application.
C#
using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Microsoft.CSharp;

class Program
{
    static void Main(string[] args)
    {
        string sources = @"
        using System;
        public static class ExampleClass
        {
            public static void ExampleMethod()
            {
                Console.WriteLine(""Hello World!"");
            }
        }";

        CSharpCodeProvider codeProvider = new CSharpCodeProvider();
        string Output = "Out.dll";

        CompilerParameters parameters = new CompilerParameters()
        {
            GenerateExecutable = false,
            OutputAssembly = Output
        };
        CompilerResults results = codeProvider.CompileAssemblyFromSource(
            parameters, sources);

        if (results.Errors.Count > 0)
        {
            foreach (CompilerError CompErr in results.Errors)
            {
                Console.WriteLine(
                            "Line number " + CompErr.Line +
                            ", Error Number: " + CompErr.ErrorNumber +
                            ", '" + CompErr.ErrorText + ";");
            }
        }
        else
        {
            // successfull compile, try to load what we just compiled
            Assembly myAssembly = Assembly.Load(File.ReadAllBytes("Out.dll"));

            // load the class;
            Type myType = myAssembly.GetType("ExampleClass");

            // get the method;
            MethodInfo mi = myType.GetMethod("ExampleMethod");

            // execute
            mi.Invoke(null, null);
        }

        Console.WriteLine("Hit any user to continue");
        Console.ReadKey();
    }

Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
BillWoodruff16-Nov-13 4:14
professionalBillWoodruff16-Nov-13 4:14 
QuestionRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
jojoba201116-Nov-13 6:41
jojoba201116-Nov-13 6:41 
AnswerRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
Eddy Vluggen16-Nov-13 9:35
professionalEddy Vluggen16-Nov-13 9:35 
AnswerRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
turbosupramk316-Nov-13 1:30
turbosupramk316-Nov-13 1:30 
SuggestionRe: How to execute c# statment in a string?(Compiling and Running code at runtime) Pin
CHill6016-Nov-13 8:06
mveCHill6016-Nov-13 8:06 
AnswerSolved! Pin
Member 94738092-Dec-13 0:10
Member 94738092-Dec-13 0:10 
QuestionHow to query Scom 2012 through c sharp? Pin
turbosupramk315-Nov-13 10:48
turbosupramk315-Nov-13 10:48 
AnswerRe: How to query Scom 2012 through c sharp? Pin
Eddy Vluggen16-Nov-13 1:10
professionalEddy Vluggen16-Nov-13 1:10 
GeneralRe: How to query Scom 2012 through c sharp? Pin
turbosupramk316-Nov-13 1:26
turbosupramk316-Nov-13 1:26 
QuestionPreventing Tread Starvation - Best Practices Pin
Foothill15-Nov-13 6:52
professionalFoothill15-Nov-13 6:52 
AnswerRe: Preventing Tread Starvation - Best Practices Pin
Ron Beyer15-Nov-13 7:05
professionalRon Beyer15-Nov-13 7:05 
GeneralRe: Preventing Tread Starvation - Best Practices Pin
Foothill15-Nov-13 8:21
professionalFoothill15-Nov-13 8:21 
AnswerRe: Preventing Tread Starvation - Best Practices Pin
Matt T Heffron15-Nov-13 11:13
professionalMatt T Heffron15-Nov-13 11:13 
GeneralRe: Preventing Tread Starvation - Best Practices Pin
Foothill15-Nov-13 14:04
professionalFoothill15-Nov-13 14:04 
GeneralRe: Preventing Tread Starvation - Best Practices Pin
Matt T Heffron15-Nov-13 14:10
professionalMatt T Heffron15-Nov-13 14:10 
GeneralRe: Preventing Tread Starvation - Best Practices Pin
Matty2217-Nov-13 22:24
Matty2217-Nov-13 22:24 
AnswerAccording to the internet Pin
Ennis Ray Lynch, Jr.15-Nov-13 7:46
Ennis Ray Lynch, Jr.15-Nov-13 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.