2011-12-08 34 views
0

我想使用存儲過程動態生成水晶報表。我使用RAS進程內sdk。我已經創建了數據集報告。 我使用的代碼如下:基於存儲過程創建水晶報表

ISCRProcedure proc1 = new Procedure(); 
     CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnectionInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo(); 
     ISCRPropertyBag logonAttributes = new PropertyBag(); 
     PropertyBag connectionAttributes = new PropertyBag(); 
     logonAttributes.Add("Data Source", datasource); 
     logonAttributes.Add("Initial Catalog", "Northwind"); 
     logonAttributes.Add("Provider", "SQLOLEDB"); 
     connectionAttributes.Add("Database DLL", "crdb_ado.dll"); 
     connectionAttributes.Add("QE_DatabaseType", "OLE DB (ADO)"); 
     connectionAttributes.Add("QE_LogonProperties", logonAttributes); 
     connectionAttributes.Add("QE_SQLDB", true); 
     connectionAttributes.Add("Server Name", servername); 
     connectionAttributes.Add("SSO Enabled", false); 
     newConnectionInfo.Attributes = connectionAttributes; 
     newConnectionInfo.UserName = username; 
     newConnectionInfo.Password = password; 
     newConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE; 
     proc1.ConnectionInfo = newConnectionInfo; 
     proc1.Name = "sp_SelectAllOrders"; 
     oReportClientDocument.DatabaseController.AddTable(proc1); 

我不知道如何訪問該存儲過程的輸出,以將其作爲數據源的報表字段後。任何想法?

回答

0

如果你想看到一個工作的例子,我有一個免費的C#類對象的創建者,數據層的創造者和位於存儲過程產生: http://radstudio.codeplex.com

RAD Studio創建一個100%的存儲過程數據驅動層;

下面的代碼來自MS應用程序塊,但是我上面的代碼生成器下載了這個類的包裝器,使它更容易;

private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType, 
     string commandText, DataSet dataSet, string[] tableNames, 
     params SqlParameter[] commandParameters) 
    { 
     if (connection == null) throw new ArgumentNullException("connection"); 
     if (dataSet == null) throw new ArgumentNullException("dataSet"); 

     // Create a command and prepare it for execution 
     SqlCommand command = new SqlCommand(); 
     bool mustCloseConnection = false; 
     PrepareCommand(command, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); 

     // Create the DataAdapter & DataSet 
     using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command)) 
     { 

      // Add the table mappings specified by the user 
      if (tableNames != null && tableNames.Length > 0) 
      { 
       string tableName = "Table"; 
       for (int index = 0; index < tableNames.Length; index++) 
       { 
        if (tableNames[index] == null || tableNames[index].Length == 0) throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames"); 
        dataAdapter.TableMappings.Add(tableName, tableNames[index]); 
        tableName += (index + 1).ToString(); 
       } 
      } 

      // Fill the DataSet using default values for DataTable names, etc 
      dataAdapter.Fill(dataSet); 

      // Detach the SqlParameters from the command object, so they can be used again 
      command.Parameters.Clear(); 
     } 

     if (mustCloseConnection) 
      connection.Close(); 
    } 
+0

是否沒有RAS sdk的示例?我想避免使用存儲過程填充數據集。 – Rahma