Amit Aggarwal

Amit Aggarwal

  • NA
  • 1
  • 769

Reporting Service in ASP.NEt Using C#

Mar 2 2015 11:53 PM
I get this Error "
  • A data source instance has not been supplied for the data source 'DataSet1'.
"
instance is there...help me out please 
My code is Correct...??
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
UserInformation dsEmployees = GetData("select top 10 * from UserInformation");
ReportDataSource datasource = new ReportDataSource("UserInformation", dsEmployees.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
private UserInformation GetData(string query)
{
string conString = @"Data Source=######;Initial Catalog=Example;Integrated Security=True";
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (UserInformation dsEmployees = new UserInformation())
{
sda.Fill(dsEmployees, "DataTable1");
return dsEmployees;
}
}
}
}
}
 

Answers (1)