Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends.
I want to show my report in report viewer but it dosen't show for me.
This my code:
C#
private void buttonX1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=FADAEILAPTOP-PC;Initial Catalog=ClerksEvaluation;Integrated Security=True");

            DataSet set = new DataSet();
            DataTable dtbl = new DataTable("DataTable1");

            SqlDataAdapter adp = new SqlDataAdapter();
            adp.SelectCommand = new SqlCommand();
            adp.SelectCommand.Connection = con;

            adp.SelectCommand.CommandText = "Report";
            adp.SelectCommand.CommandType = CommandType.StoredProcedure;

            adp.SelectCommand.Parameters.AddWithValue("@clrk_Name", name.Text);
            adp.SelectCommand.Parameters.AddWithValue("@clrk_Family", family.Text);
            adp.SelectCommand.Parameters.AddWithValue("@clrk_MelliCode", melli.Text);
            SqlDateTime az_d = SqlDateTime.Parse(az.Text);
            adp.SelectCommand.Parameters.AddWithValue("@AzTarikh", az_d);
            SqlDateTime ela_d = SqlDateTime.Parse(ela.Text);
            adp.SelectCommand.Parameters.AddWithValue("@Ela", ela_d);
            adp.Fill(set, "DataTable1");

            Form1 f1 = new Form1();

            
            ReportDataSource source = new ReportDataSource("datatable1", dtbl);
            f1.reportViewer1.Visible = true;
            f1.reportViewer1.ProcessingMode = ProcessingMode.Local;
            f1.reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
            f1.reportViewer1.LocalReport.DataSources.Clear();
            f1.reportViewer1.LocalReport.DataSources.Add(source);

            f1.reportViewer1.LocalReport.Refresh();
            f1.Show();
        }


this doesn't have any error.
this is my procedure and it doesn't have error.

SQL
USE [ClerksEvaluation]
GO
/****** Object:  StoredProcedure [dbo].[Report]    Script Date: 02/06/2013 09:17:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Report]

@clrk_Name	Nvarchar(50),
@clrk_Family		Nvarchar(60),
@clrk_MelliCode		Char(10),
@AzTarikh			Date,
@Ela				Date

AS

Declare @id int
select @id = clrk_Id from Clerk 
where clrk_Name = @clrk_Name and clrk_Family = @clrk_Family and clrk_MelliCode = @clrk_MelliCode

select  clrk_Name,clrk_Family,clrk_MelliCode,clrk_FatherName, epcnt_Name, clrke_Percent, clrke_Tozihat, clrke_Date, clrke_Hafteh  
from ClerkEvaluation
inner join Clerk on Clerk.clrk_Id = @id
inner join EvaluationPercent on ClerkEvaluation.epcnt_Id = EvaluationPercent.epcnt_Id
where clrke_Date Between @AzTarikh and @Ela


my ReportViewer binded to procedure.
Could you help me?
Posted
v2
Comments
Sandeep Mewara 6-Feb-13 1:36am    
Can you please change your dataset name from keyword 'set' to something else? See if that works.
Elham.Deljooei 6-Feb-13 1:53am    
I did your suggest but it doesn't show to me.
Could you tell me What i have to do step by step for report viewer and procedure. I think i don't did it properly?
RDBurmon 6-Feb-13 2:02am    
Start the SQL profiler and run this report and see what query you received in profiler.
then run this query manually and see if you get result from sql database.
Elham.Deljooei 6-Feb-13 2:11am    
Start the SQL profiler and run this report and see what query you received in profiler.
I don't underestand, what's you mean?
Elham.Deljooei 7-Feb-13 0:01am    
Nobody couldn't help me?????????? :=(
I would like to solve this problem.

1 solution

Hi everyone
I did it.


private void buttonX1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=FADAEILAPTOP-PC;Initial Catalog=ClerksEvaluation;Integrated Security=True");

DataSet a = new DataSet();
DataTable dtbl = new DataTable();

SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand();
adp.SelectCommand.Connection = con;

adp.SelectCommand.CommandText = "Report";
adp.SelectCommand.CommandType = CommandType.StoredProcedure;

adp.SelectCommand.Parameters.AddWithValue("@clrk_Name", name.Text);
adp.SelectCommand.Parameters.AddWithValue("@clrk_Family", family.Text);
adp.SelectCommand.Parameters.AddWithValue("@clrk_MelliCode", melli.Text);
SqlDateTime az_d = SqlDateTime.Parse(az.Text);
adp.SelectCommand.Parameters.AddWithValue("@AzTarikh", az_d);
SqlDateTime ela_d = SqlDateTime.Parse(ela.Text);
adp.SelectCommand.Parameters.AddWithValue("@Ela", ela_d);
adp.Fill(dtbl);
//SqlCommand cmd = new SqlCommand("report", con);
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.AddWithValue("@clrk_Name", name.Text);
//cmd.Parameters.AddWithValue("@clrk_Family", name.Text);
//cmd.Parameters.AddWithValue("@clrk_MelliCode", name.Text);
//SqlDateTime az_d = SqlDateTime.Parse(az.Text);
//cmd.Parameters.AddWithValue("@AzTarikh", az_d);
//SqlDateTime ela_d = SqlDateTime.Parse(ela.Text);
//cmd.Parameters.AddWithValue("@Ela", ela_d);
//SqlDataAdapter da = new SqlDataAdapter(cmd);
//DataTable dt = new DataTable();
//da.Fill(dt);

Form1 f1 = new Form1();


//ReportDataSource source = new ReportDataSource("datatable1", dtbl);
f1.reportViewer1.Visible = true;
//f1.reportViewer1.ProcessingMode = ProcessingMode.Local;
//f1.reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
f1.reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource source = new ReportDataSource("DataSet1", dtbl);
f1.reportViewer1.LocalReport.DataSources.Add(source);
f1.reportViewer1.LocalReport.Refresh();

f1.Show();

"DataSet1" is name of report's data source. Therefor you can see in Report's smart tag and choose Choose Data Source.
Good luck Friends.


}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900