[英]SQL Server Reporting Services - Report Expressions Execution
Say I have the following expression: 说我有以下表达:
=DateAdd(DateInterval.Year,-1,Today())
Is there a SQL Server web service endpoint that'll allow me to pass in an expression and return the result of the executed expression? 是否有一个SQL Server Web服务终结点,该终结点将允许我传递一个表达式并返回执行后的表达式的结果? I looked through the endpoints listed here but couldn't find one.
我浏览了此处列出的端点,但找不到端点。
Or is there another way to evaluate this expression? 还是有另一种方法可以评估此表达式?
I've found another way to evaluate the expression using VB.net (This assumes that @Wolfgang Kais is correct about VB.net use instead of VBA) 我发现了使用VB.net评估表达式的另一种方法(这假定@Wolfgang Kais对于使用VB.net而不是VBA是正确的)
Here is the code snippet: 这是代码片段:
using System;
using System.CodeDom.Compiler;
using System.Text;
using Microsoft.VisualBasic;
namespace VbStringCompiler
{
internal class Program
{
public static void Main(string[] args)
{
new Program();
}
private const string CRLF = "\r\n";
private Program()
{
var vbCodeProvider = new VBCodeProvider();
var compilerParameters = new CompilerParameters();
compilerParameters.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");
compilerParameters.ReferencedAssemblies.Add("System.dll");
compilerParameters.CompilerOptions = "/t:library";
compilerParameters.GenerateInMemory = true;
var stringBuilder = new StringBuilder();
stringBuilder.Append("Imports Microsoft.VisualBasic" + CRLF);
stringBuilder.Append("Imports System" + CRLF + CRLF);
stringBuilder.Append("Namespace Evaluate" + CRLF);
stringBuilder.Append("Class RunTime" + CRLF);
stringBuilder.Append("Public Function Run() As Object" + CRLF);
// insert code to return
stringBuilder.Append("Return DateAdd(DateInterval.Year, -1, Today())" + CRLF);
stringBuilder.Append("End Function" + CRLF);
stringBuilder.Append("End Class" + CRLF);
stringBuilder.Append("End Namespace" + CRLF);
try
{
var compilerResults =
vbCodeProvider.CompileAssemblyFromSource(compilerParameters, stringBuilder.ToString());
if (compilerResults.Errors.Count > 0)
{
foreach (CompilerError compilerError in compilerResults.Errors)
{
Console.Error.WriteLine(compilerError.ToString());
}
return;
}
var instance = compilerResults.CompiledAssembly.CreateInstance("Evaluate.RunTime");
var methodInfo = instance.GetType().GetMethod("Run");
var methodReturn = methodInfo.Invoke(instance, null);
Console.WriteLine(methodReturn);
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.