SqlCommand cmd = new SqlCommand("select Developer from Stackoverflow
where UserID='786' and Developer='Sufiyan'", con);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
string codeSnippet = reader["CodeSnippet"].ToString();
dynamic script =
CSScript.LoadCode(@"
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
public class RunFromSqlServer
{
public void RunCode(string developer){" + codeSnippet + "}"+
"}").CreateObject("*");script.RunCode("Mohammad Sufiyan Shaikh");
}
if (con.State == ConnectionState.Open)
{
con.Close();
}
其中 codeSnippet 可以是您想要运行的任何 c# 代码我已经发布了这个问题以及帮助其他人的答案..