I created a report dealing with expense tracker. I need based on income details report should display.
Now i get the whole report but does not change when i change income details from a common filter option: incomedetails.
when i use salary filter only incomedetails with salary should be displayed.
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Rdlc_Report
{
public partial class Form1 : Form
{
DataTable dtexpense = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Getincomedet();
// TODO: This line of code loads data into the 'ExpenseTrackerDataSet.ExpenseTable' table. You can move, or remove it, as needed.
this.ExpenseTableTableAdapter.Fill(this.ExpenseTrackerDataSet.ExpenseTable);
this.reportViewer1.RefreshReport();
this.reportViewer1.RefreshReport();
}
private ExpenseTrackerDataSet GetData(string query)
{
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection("xxx"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
String val = this.ComboBox1.Text;
cmd.Parameters.AddWithValue("@IncomeDetails", val);
sda.SelectCommand = cmd;
using (ExpenseTrackerDataSet dsexp1 = new ExpenseTrackerDataSet())
{
sda.Fill(dsexp1,"dtexpense");
return dsexp1;
}
}
}
}
private void Getincomedet()
{
SqlCommand cmd = new SqlCommand("SELECT distinct IncomeDetails FROM ExpenseTable ");
using (SqlConnection con = new SqlConnection("xxx"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dtexpense);
ComboBox1.DataSource = dtexpense;
ComboBox1.DisplayMember = "IncomeDetails";
ComboBox1.ValueMember = "IncomeDetails";
// comboBox1.Items.Insert(0, new ListItem("Select", ""));
}
}
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.ExpenseTableTableAdapter.Fill(this.ExpenseTrackerDataSet.ExpenseTable);
if (ComboBox1.SelectedIndex != 0)
{
//this.reportViewer1.LocalReport.DataSources.Clear();
ExpenseTrackerDataSet dsexp = GetData("SELECT * FROM ExpenseTable WHERE IncomeDetails = @IncomeDetails");
ReportDataSource dsexp1 = new ReportDataSource("Expense", dsexp.Tables[3]);
//this.reportViewer1.RefreshReport();
//this.reportViewer1.RefreshReport();
this.reportViewer1.LocalReport.DataSources.Add(dsexp1);
// this.reportViewer1.RefreshReport();
}
}
}
}
please solve.