I'm trying to make a button to load and filter my ReportViewer by name but the output is data source instance not supplied. Here is my code:
private void btnReport_Click(object sender, EventArgs e)
{
String sql = "Select * from practise Where name ='" + textBox1.Text + "'";
SqlConnection con = new SqlConnection(ConnectionString);
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
adp.Fill(ds);
ReportDataSource rds = new ReportDataSource("practise", ds.Tables[0]);
reportViewer2.ProcessingMode = ProcessingMode.Local;
reportViewer2.LocalReport.ReportPath = "Report1.rdlc";
if (ds.Tables[0].Rows.Count > 0)
{
reportViewer2.LocalReport.DataSources.Clear();
reportViewer2.LocalReport.DataSources.Add(rds);
reportViewer2.RefreshReport();
}
This could be simple. Please check that your dataset name in the report is not "DataSet1" by default. Also, make sure that the path for report is correct. Here is a working example:
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DemoDB"].ConnectionString))
{
String sql = "Select * from practise Where name ='" + textBox1.Text + "'";
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
adp.Fill(ds);
ReportDataSource rds = new ReportDataSource("DataSet1", ds.Tables[0]);
reportViewer2.ProcessingMode = ProcessingMode.Local;
reportViewer2.LocalReport.ReportPath = "Report1.rdlc";
if (ds.Tables[0].Rows.Count > 0)
{
reportViewer2.LocalReport.DataSources.Clear();
reportViewer2.LocalReport.DataSources.Add(rds);
reportViewer2.RefreshReport();
}
}
I hope that would help someone.
Related
When I type in my search box my Data grid view doesn't show the data that i typed in even though its in the database. This is my codes for the search box
MySqlConnection con = new MySqlConnection(MyConnectionString);
con.Open();
MySqlDataAdapter adapt = new MySqlDataAdapter();
con = new MySqlConnection(MyConnectionString);
adapt = new MySqlDataAdapter("SELECT * from tblregister where FirstName like '" + textBox1.Text + "%'", con);
DataTable ds = new DataTable();
DataSet dt = new DataSet();
adapt.Fill(dt);
dataGridView1.DataSource =ds;
I want to display report in my admin panel when I select the sales person from dropdown list in my page but nothing is displayed and display some error here.
Below is my code:
protected void BtnViewReport_Click(object sender, EventArgs e)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/SalesPerson.rdlc");
DataSet ds = GetData("select * from customer_new where salesperson in (select +
email from Registration where name='" + ddsalesperson.SelectedValue.ToString() +
"')");
ReportDataSource datasource = new ReportDataSource("customer_new",ds.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
private DataSet GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds, "customer_new");
return ds;
}
}
}
}
and I get the following error :
A data source instance has not been supplied for the data source
'DataSet1'.
That error means that the dataset "DataSet1" has not recieved data. I'd take a guess that the dataset "customer_new" doesn't actually exist, or if it does you have 2 datasets, one of which you may or may not be using.
Try:
ReportDataSource datasource = new ReportDataSource("DataSet1",ds.Tables[0]);
This is with reference to my previous question "Report not showing up on report viewer"
I am developing a c# application where I need to generate a report. I am a using a dataset which is filled with the data coming from a stored procedure which takes one parameter from the C# code. I am creating a parameter in report1.rdlc and populating it with the data from a textbox. When I run the application I can see only column headers on the report while as it does’t show any data on the report viewer.
My code below
public void GenerateBranchwiseReport()
{
conn.Open();
SqlCommand BranchReportcmd = new SqlCommand("select [am/bsi name] from masterlookup where [asc type]='BRANCH' group by [am/bsi name]", conn);
SqlDataReader BranchReportread = BranchReportcmd.ExecuteReader();
while (BranchReportread.Read())
{
BranchManagerName.Add(BranchReportread.GetValue(0).ToString());
}
conn.Close();
foreach (string managername in BranchManagerName)
{
conn.Open();
SqlCommand GetReportDatacmd = new SqlCommand();
GetReportDatacmd.CommandText = "USP_BranchwiseReport";
GetReportDatacmd.CommandType = CommandType.StoredProcedure;
GetReportDatacmd.Parameters.Add(new SqlParameter("#BranchManagerName", managername));
GetReportDatacmd.Connection = conn;
GetReportDatacmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(GetReportDatacmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
reportViewer1.Reset();
this.reportViewer1.Visible = true;
string reportname = #"d:\users\administrator\documents\visual studio 2010\Projects\ReportwithParameter\ReportwithParameter\Report1.rdlc";
this.reportViewer1.LocalReport.ReportPath = #"d:\users\administrator\documents\visual studio 2010\Projects\ReportwithParameter\ReportwithParameter\Report1.rdlc";
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("ManagerName", managername);
this.reportViewer1.LocalReport.SetParameters(param);
ReportDataSource ReportBranch = new ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]);
this.reportViewer1.LocalReport.ReportEmbeddedResource = reportname;
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]));
//this.reportViewer1.LocalReport.DataSources.Add(ReportBranch);
this.reportViewer1.LocalReport.Refresh();
//SendEmail();
}
public void GenerateBranchwiseReport()
{
string ManagerNames="";
conn.Open();
SqlCommand BranchReportcmd = new SqlCommand("select [am/bsi name] from masterlookup where [asc type]='BRANCH' group by [am/bsi name]", conn);
SqlDataReader BranchReportread = BranchReportcmd.ExecuteReader();
while (BranchReportread.Read())
{
if (ManagerNames.length==0)
ManagerNames="'"+BranchReportread.GetValue(0).ToString()+"'";
else
ManagerNames =ManagerNames + ",'" + BranchReportread.GetValue(0).ToString()+ "'";
}
conn.Close();
//So now, You have Multiple Managers in ManagerNames string You can send it to SQL, which must used in Where clause with IN (#Managers) in you Stored Procedure.
conn.Open();
SqlCommand GetReportDatacmd = new SqlCommand();
GetReportDatacmd.CommandText = "USP_BranchwiseReport";
GetReportDatacmd.CommandType = CommandType.StoredProcedure;
GetReportDatacmd.Parameters.Add(new SqlParameter("#BranchManagerName", ManagerNames));
GetReportDatacmd.Connection = conn;
GetReportDatacmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(GetReportDatacmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
reportViewer1.Reset();
this.reportViewer1.Visible = true;
string reportname = #"d:\users\administrator\documents\visual studio 2010\Projects\ReportwithParameter\ReportwithParameter\Report1.rdlc";
this.reportViewer1.LocalReport.ReportPath = #"d:\users\administrator\documents\visual studio 2010\Projects\ReportwithParameter\ReportwithParameter\Report1.rdlc";
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("ManagerName", managername);
this.reportViewer1.LocalReport.SetParameters(param);
ReportDataSource ReportBranch = new ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]);
this.reportViewer1.LocalReport.ReportEmbeddedResource = reportname;
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]));
//this.reportViewer1.LocalReport.DataSources.Add(ReportBranch);
this.reportViewer1.LocalReport.Refresh();
//SendEmail();
hi everyone i have this code here
SqlConnection con = new SqlConnection(Properties.Settings.Default.StoreDBConnection);
SqlDataAdapter da = new SqlDataAdapter();
private void Form1_Load(object sender, EventArgs e)
{
String test = DateTime.Now.ToString("yyyy-MM-dd");
var dept = Properties.Settings.Default.GiftDepartment;
MessageBox.Show(""+test+"");
SqlCommand cmd = new SqlCommand("SELECT DeptNo,DeptSales,DeptCustomers FROM StoreSalesDetail where DeptNo="+dept+" and ProcDate>="+test+"", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet1 ds = new DataSet1();
da.Fill(ds);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", ds.Tables[1]));
this.reportViewer1.RefreshReport();
}
Sample data in my table
2013-05-03 00:00:00.000,2,120.0000,1,1
2013-05-04 00:00:00.000,2,50.0000,1,1
test returns the date 2013-05-04 so why does my report return both date in the >= query?
try using datediff for more precision. Do wrap input value [test] in single quotes.
SqlCommand cmd = new SqlCommand("SELECT DeptNo,DeptSales,DeptCustomers FROM StoreSalesDetail where DeptNo="+dept+" and datediff(d, '" + test + "', ProcDate) >=0", con);
i am having Report page in my windows project .In that i included microsoftReportViewer . In that page two combobox is there .items in 1st combobox are:
FirmDetails
ChittyHolding
LoanDetails.
Corresponding to selection this items in combobox1, items in combobox will change .I need report According to this values in 2 combbox.
My code is like
if (cbReprt.Text == "FirmDetails")
{
if (cbGeneral.Text == "AllFirmDetails")
{
reportViewer1.RefreshReport();
SqlConnection con = new SqlConnection("Data Source=202.88.231.102;Initial Catalog=dbs_Merchant;Persist Security Info=True;User ID=sa;Password=abc123*");
con.Open();
allfirmdetails ds = new allfirmdetails();
string str = "Select * from View_2";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
DataTable dt = new DataTable();
da.Fill(dt);
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
reportViewer1.LocalReport.ReportPath = "F:\\MerchantAssociation\\MerchantAssociation\\Report7.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("allfirmdetails_View_2", dt));
reportViewer1.RefreshReport();
}
else
{
reportViewer1.RefreshReport();
SqlConnection con = new SqlConnection("Data Source=202.88.231.102;Initial Catalog=dbs_Merchant;Persist Security Info=True;User ID=sa;Password=abc123*");
con.Open();
allfirmdetails ds1 = new allfirmdetails();
string str1 = "Select * from View_2 where FirmName='" + cbGeneral.Text + "'";
SqlCommand cmd1 = new SqlCommand(str1, con);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
da1.Fill(ds1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
reportViewer1.LocalReport.ReportPath = "F:\\MerchantAssociation\\MerchantAssociation\\firmwise.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("allfirmdetails_View_2", dt1));
reportViewer1.RefreshReport();
}
}
else if (cbReprt.Text == "ChittyDetails")
{
if (cbGeneral.Text == "AllChittyDetails")
{
reportViewer1.RefreshReport();
SqlConnection con = new SqlConnection("Data Source=202.88.231.102;Initial Catalog=dbs_Merchant;Persist Security Info=True;User ID=sa;Password=abc123*");
con.Open();
ChittyDetails ds2 = new ChittyDetails();
string str2 = "Select * from View_1";
SqlCommand cmd2 = new SqlCommand(str2, con);
SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
da2.Fill(ds2);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
reportViewer1.LocalReport.ReportPath = "F:\\MerchantAssociation\\MerchantAssociation\\allchitty.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("ChittyDetails_View_1", dt2));
reportViewer1.RefreshReport();
}
First I select chittyholding details. Then I got the report. Then I select chitty details report, I got the error like
**An error occured during local report processing .A data sourcr instance has not been supplied for the data source "ChittyHolding_View_7"**. If I close and run the project again ,then that firmdetails selection will work.But another will not work.It means Only for one selection I am getting the report. Why? Please solve this error
Try to call reportViewer1.Reset(); instead of reportViewer1.Refresh(); at the beginning of every condition