Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Working with Stored Procedure within the SharpDevelop Report

$
0
0

Hi everybody,

I am trying to design or develop a report that will be generated by a filter, for instance: by a gender (SELECT * FROM Customer WHERE gender = 'M') and this is using the stored procedure as indicated below:

 

-------------------------->>>

  1. set ANSI_NULLS ON
  2. set  QUOTED_INDENTIFIER ON
  3. go
  4. ALTER PROCEDURE [dbo].[_FilterByGender]
  5.               @gen nchar(1)
  6. AS
  7.   BEGIN
  8.       SET NOCOUNT ON;
  9.             select firstname, lastname, gender, race from customer where gender = @gen;
  10.   END 

------------------------------------>>>>

 

Below is my source code which gives me an error message that "Procedure or Function '_FilterByGender' expects parameter '@gen', which was not supplied."

 

----------------------->>>>>

  1. void Button11Click(object sender, EventArgs e) //Report Generator
  2.         {
  3.             ReportEngine engine = new ReportEngine ();
  4.             
  5.             ReportParameters repParam = ReportEngine.LoadParameters (reportPath);
  6.             
  7.             DbProviderFactory factory = DbProviderFactories.GetFactory 
  8.                 (css.ProviderName);
  9.             DbConnection conn = factory.CreateConnection ();
  10.             
  11. //            ReportModel reportModel = ReportEngine.LoadReportModel (reportPath);
  12.             
  13. //            repParam.SqlParameters[0].DataType = DbType.String;
  14. //            repParam.SqlParameters[0].ParameterDirection = ParameterDirection.Input;
  15. //            repParam.SqlParameters[0].ParameterName = "@gen";
  16. //            repParam.SqlParameters[0].ParameterValue = comboBox1.Text;
  17.             
  18.             repParam.SqlParameters.Add (new ICSharpCode.Reports.Core.SqlParameter ("@gen",
  19.                                                           DbType.String, comboBox1.Text)); //comboBox1 contains gender values 'M' & 'F'
  20.             
  21.             BasePager pageBuilder = engine.CreatePageBuilder
  22.                 (reportPath, repParam);

  23.             pageBuilder.BuildExportList ();
  24.             
  25.             engine.PreviewStandardReport (reportPath, repParam);            
  26.         }

----------------------------->>>>>

 

Kindly note that I have also tried commenting the following code:

 

repParam.SqlParameters.Add (new ICSharpCode.Reports.Core.SqlParameter ("@gen",
                                                          DbType.String, comboBox1.Text));

 

and uncommenting the following one:

 

//            repParam.SqlParameters[0].DataType = DbType.String;
//            repParam.SqlParameters[0].ParameterDirection = ParameterDirection.Input;
//            repParam.SqlParameters[0].ParameterName = "@gen";
//            repParam.SqlParameters[0].ParameterValue = comboBox1.Text;

 

and when the above code is uncommented, the following error is obtained:

"Index was out of range. Must be non-negative and less than the size of the collection."

 

Values for ReportProperties on the Report2.srd are as follow

 

  1. FileName: C:\Users\Pee-Jay\Documents\SharpDevelop Projects\TestApp\TestApp\Report2.srd
  2. ReportName: Report2
  3. ReportType: DataReport
  4. CommandText: _FilterByGender
  5. CommandType: StoredProcedure
  6. ConnectionString: Provider=SQLNCLI10.1;Data Source=;User Id=XXXXXX;Password=XXXXXX;Initial Catalog=TestDB
  7. DataModel: PullData
  8. ParameterCollection: <nothing specified>
  9. SqlParameters: <nothing specified>

 

--------------------------->>>

 

I have tried getting this right on my own for more than a month now wiithout any luck. Please help fellows.

 

Thanks


Viewing all articles
Browse latest Browse all 1764

Trending Articles