1
Answer

How to pass dataset to a report in C#.NET

Ask a question
Hi,
 

I want to connect my Report with with a dataset variable which is declared global in my page, but this i cannot somehow connect with the Dataset1 in Report1.rdlc.

Here's the code:-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using srusti_mobilecafe;
using System.Data.SqlClient;
using Microsoft.Reporting;
using Microsoft.Reporting.WinForms;


namespace srusti_mobilecafe
{
public partial class expenseReport : Form
{
public expenseReport()
{
InitializeComponent();
}

private void expenseReport_Load(object sender, EventArgs e)
{

//string strConnectionString = @"Data Source=arya021;AttachDbFilename=C:\Documents and Settings\employee\Desktop\member\srusti_mobilecafe\srusti_mobilecafe\AryaBlue1_Mobilecafe.mdf;Integrated Security=True";
//SqlDataAdapter da = new SqlDataAdapter();
//SqlCommand cmd = new SqlCommand("sp_GetProject " + "'0660CAD6-6F1A-4D19-A1FD-17BF3655AC98'");
//cmd.CommandType = CommandType.Text;
//cmd.Connection = new SqlConnection(strConnectionString);
//da.SelectCommand = cmd;

//da.Fill(Program.ds, "DataSet1");
reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", Program.ds.Tables[0]));
this.reportViewer1.RefreshReport();
reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
}
}
}

Answers (1)