how to connect reportviewer to dataset
-
hi sir i am connecting the reportviewer to dataset but i am fail.i am using following code.please help me. using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using Microsoft.Reporting.WebForms; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ReportViewer1.Visible = false; } protected void Button1_Click(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { ReportViewer1.Visible = true; SqlConnection con = new SqlConnection("server=DC-12\\SQLSERVER2005;uid=sa;pwd=start;database=Vikas_Data"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "seldata"; string pn = TextBox1.Text; cmd.Parameters.AddWithValue("@pn", pn); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = con; SqlDataAdapter adap = new SqlDataAdapter(); adap.SelectCommand = cmd; DataSet ds = new DataSet (); adap.Fill(ds, "table"); ReportViewer1.LocalReport.ReportPath = "MyFirst.rdlc"; ReportDataSource rds = new ReportDataSource(); rds.value=ds.Tables[0]; ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh(); } } there is no error .but data will not be show in report viewer. please help me .as soon as possible .what may be the issue.
-
hi sir i am connecting the reportviewer to dataset but i am fail.i am using following code.please help me. using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using Microsoft.Reporting.WebForms; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ReportViewer1.Visible = false; } protected void Button1_Click(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { ReportViewer1.Visible = true; SqlConnection con = new SqlConnection("server=DC-12\\SQLSERVER2005;uid=sa;pwd=start;database=Vikas_Data"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "seldata"; string pn = TextBox1.Text; cmd.Parameters.AddWithValue("@pn", pn); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = con; SqlDataAdapter adap = new SqlDataAdapter(); adap.SelectCommand = cmd; DataSet ds = new DataSet (); adap.Fill(ds, "table"); ReportViewer1.LocalReport.ReportPath = "MyFirst.rdlc"; ReportDataSource rds = new ReportDataSource(); rds.value=ds.Tables[0]; ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh(); } } there is no error .but data will not be show in report viewer. please help me .as soon as possible .what may be the issue.
You might want to try clearing the existing data sources first with Me.ReportViewer1.LocalReport.DataSources.Clear() and possibly in the form.designer.vb comment out the lines which would have been added if/when you selected the report using the ReportViewer Tasks box 'Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource and 'ReportDataSource1.Value = 'Me.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource1) I have found that almost every problem I've had with report viewer not displaying the report was to do with data in some way or another. Have you confirmed that your adap.fill line is actually putting some records into the dataset? Hope this is of some help.