添加ADOMD参数编程C# [英] Adding Adomd parameters programmatically C#
问题描述
下午所有。
我建立一个web应用程序,我试图通过从SSAS多维数据集的一些数据来拉。
I'm building a web app and I'm attempting to pull through some data from an SSAS cube.
我有以下MDX我想在C#中,但与添加几个参数,即2 parameteres,一个用于公司123,另一个位置1复制:
I have the following MDX I would like to replicate in c# but with adding a few parameters i.e. two parameteres, one for company 123 and another for location 1:
@"SELECT NON EMPTY([Dim Unit].[All Units].[Category Group Name]) ON COLUMNS
FROM [Info]
WHERE ([Dim Company].[All Companies].&[123],
[Dim Location].[All Locations].&[123]&[1])";
现在,我能得到这个启动和一个参数运行:
Now, I can get this up and running with one parameter:
AdomdCommand cmdPDC = conPDC.CreateCommand();
cmdPDC.CommandText = "SELECT [Dim Unit].[All Units].[Category Group Name].Members ON 0 FROM [Info] WHERE (StrToMember(@P1)";
string companyid = "123";
string sP1 = "[Dim Company].&" + company;
cmdPDC.Parameters.Add(new AdomdParameter("P1", sP1));
但我怎么然后实现第二个参数,例如,如果我想坚持一个参数为位置我想沿线ofbelow,但我不能让小草皮的工作:
But how do I then implement a second parameter, for example, if I wanted to stick a parameter in for location? I was thinking along the lines ofbelow but I can't get the little sod to work:
AdomdCommand cmdPDC = conPDC.CreateCommand();
cmdPDC.CommandText = "SELECT [Dim Unit].[All Units].[Category Group Name].Members ON 0 FROM [Info] WHERE (StrToMember(@P1)," + "(StrToMember(@P2))";
string companyid = "123";
string locationid = "1";
string sP1 = "[Dim Company].&" + company;
string sP2 = "[Dim Location].&" + company + "&" + location;
cmdPDC.Parameters.Add(new AdomdParameter("P1", sP1));
cmdPDC.Parameters.Add(new AdomdParameter("P2", sP2));
任何帮助或建议感激地接受。
Any help or advice gratefully received.
推荐答案
一个解决方案
AdomdCommand cmdPDC = conPDC.CreateCommand();
cmdPDC.CommandText = "SELECT NON EMPTY [Dim Unit].[All Units].[Category Name].Members ON 0 FROM [MY CUBE] WHERE (StrToMember(@CompanyId),StrToMember(@LocationId))";
string companyid = "[123]";
string locationid = "[1]";
string sCompanyId = "[Dim Company].&" + companyid;
string sLocationId = "[Dim Location].&" + companyid + "&" + locationid;
cmdPDC.Parameters.Add(new AdomdParameter("CompanyId", sCompanyId));
cmdPDC.Parameters.Add(new AdomdParameter("LocationId", sLocationId));
和一些小球。
您可能会收到此错误:
解决方案:当带引号的字符串中插入 @CompanyId
,确保该参数不括在单引号(') - C#是聪明,会转换数据类型和在您添加这些撇号。但是,您将无法看到它在监视窗口和所有似乎是罚款。
Resolution: When inserting the @CompanyId
in the quoted string, make sure the parameter is not enclosed in apostrophes (') - c# is clever and will convert the data type and add these apostrophes in for you. However, you won't be able to see it in a watch window and all would appear to be fine.
所有项目都回来了,这样看来,你的参数。被忽略
All items are returned and it would appear that your parameters are being ignored.
解决方法:检查的第一 SELECT
,并确保它是 SELECT NON EMPTY
。
Resolution: Check the very first SELECT
and make sure it is SELECT NON EMPTY
.
这篇关于添加ADOMD参数编程C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!