I have a stored procedure named "Graph" that should get a value to the parameter #Material, and I created a report in ASP.NET that should show a chart using the data from the stored procedure.
However, when I try to load the report I get:
An error has occurred during report processing.
Cannot create a connection to data source 'PhilipsMaterialsDataSet'.
ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetData' that has no parameters.
I tried different solutions but none of them worked. Also, I'm not sure if I should declare the parameter in the ASP code.
( by the way, GetData is not recognized here because it has one parameter (#Material-from the stored procedure) and for some reason, it is called without any parameters )
The code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
public partial class StatisticsPage : System.Web.UI.Page
{
string Connectionstring = "server=(local)\\SQLEXPRESS;database=PhilipsMaterials;Integrated Security=SSPI";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void btndisplay_Click(object sender, EventArgs e)
{
BindReport();
}
private void BindReport()
{
SSRSReport report = new SSRSReport();
SqlParameter[] sqlParams = new SqlParameter[] {
new SqlParameter("#Material","453567068441")
};
string ReportDataSource = "DataSet1";
bool bind = report.CreateReport(Connectionstring, "graph", sqlParams, ref ReportViewer1, ReportDataSource);
if (bind)
{
ReportViewer1.Visible = true;
}
}
}
public class SSRSReport
{
public SSRSReport()
{
//
// TODO: Add constructor logic here
//
}
public bool CreateReport(String Connectionstring,string StoreProcedureName ,SqlParameter[] Parameter,ref Microsoft.Reporting.WebForms.ReportViewer ReportViewer,string ReportDataSource)
{
bool reportbind = false;
using (SqlConnection con = new SqlConnection(Connectionstring))
{
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = StoreProcedureName;
com.Parameters.AddRange(Parameter);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(ds);
ReportDataSource datasource = new ReportDataSource(ReportDataSource, ds.Tables[0]);
if ( ds.Tables[0].Rows.Count > 0)
{
ReportViewer.LocalReport.DataSources.Clear();
ReportViewer.LocalReport.DataSources.Add(datasource);
//This is another solution I tried:
//List<ReportParameter> lstReportParameters = new List<ReportParameter>();
//ReportParameter objReportParameter = new ReportParameter("Material", "453567068441");
//lstReportParameters.Add(objReportParameter);
//ReportViewer.LocalReport.SetParameters(lstReportParameters);
// ReportViewer.ServerReport.Refresh();
reportbind = true;
}
}
return reportbind;
}
}
The ASP code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="StatisticsPage.aspx.cs" Inherits="StatisticsPage" %>
<%# Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test SSRS</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="610px" Width="1179px" ShowParameterPrompts="true">
<LocalReport ReportPath="Report.rdlc" >
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="PhilipsMaterialsDataSetTableAdapters.GraphTableAdapter" >
</asp:ObjectDataSource>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</form>
</body>
</html>
The error is saying GetData requires some parameters, and you have to supply them by adding a parameters like like:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="PhilipsMaterialsDataSetTableAdapters.GraphTableAdapter" >
<SelectParameters>
<asp:Parameter Name="X" DefaultValue="Y" .. />
</SelectParameters>
</asp:ObjectDataSource>
Related
hi I am trying to make a log in page as well as sign up page in asp.net using 3 tier architecture by using sql server architecture. I am able to fetch data from sql server data base which I have manually inserted during table creation in database and I am able to use it in my log in page.
I have also created a sign up page but I am not able to get the values from sign up webform textbox to sqlserver database I am getting some error kindly help me with this.
I have given the connection string of sql server in web.config
my sql server table creation code
CREATE TABLE LOGINDETAILS
(USERID VARCHAR(50),
PASSWORD VARCHAR (50)
);
INSERT INTO LOGINDETAILS (USERID,PASSWORD) values( 'sam', 'pass');
web.config connection string code
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="DBcon" connectionString="Data Source=P3A-B1YH882\SQLSERVER;Initial Catalog=master;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
my business layer /middle layer code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using DataAcess;
using System.Data.SqlClient;
using System.Data.Sql;
namespace middlelayer
{
public class UserBO
{
private string _UserName = " ";
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
private string _Password = " ";
public string Password
{
get { return _Password; }
set { _Password = value; }
}
DataA da = new DataA();
public bool getUser()
{
if (da.IsValid(UserName, Password).Tables[0].Rows.Count == 0)
{
return false;
}
else
{
return true;
}
}
}
}
my datAccess layer code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
namespace DataAcess
{
public class DataA
{
string conString = ConfigurationManager.ConnectionStrings["DBcon"].ToString();
public DataSet IsValid(string UserName, string Password)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM LOGINDETAILS WHERE USERID ='" + UserName + "' and PASSWORD= '" + Password + "'", con);
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
return ds;
}
}
}
MY LOGIN PAGE CODE
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="WebApplication4.login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="height: 277px">
<form id="form1" runat="server">
<div>
<asp:Label ID="lbluserid" runat="server" BackColor="#FFFF99" BorderStyle="Ridge" Height="17px" Text="User ID" Width="52px"></asp:Label>
<asp:TextBox ID="txtuserid" runat="server" BackColor="#99FFCC" style="margin-left: 122px"></asp:TextBox>
<br />
</div>
<p>
<asp:Label ID="lblpassword" runat="server" BackColor="#FFFF99" BorderStyle="Ridge" Text="Password"></asp:Label>
<asp:TextBox ID="txtpassword" TextMode="Password" runat="server" BackColor="#99FFCC" style="margin-left: 110px" ></asp:TextBox>
</p>
<p>
</p>
<asp:Button ID="btnlogin" runat="server" BackColor="#33CCFF" BorderStyle="Ridge" OnClick="btnlogin_Click" style="margin-left: 78px" Text="Login" Width="107px" />
<p>
</p>
<asp:Label ID="Label1" runat="server" Text="NOT REGISTERED ??"></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server" BorderStyle="Outset" NavigateUrl="~/sign_up.aspx">SIGN UP</asp:HyperLink>
</form>
</body>
</html>
* MY SIGN UP PAGE CODE*
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="sign_up.aspx.cs" Inherits="WebApplication4.sign_up" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="lblssignup" runat="server" BackColor="#FF99CC" Text="SIGN UP"></asp:Label>
<br />
<br />
<p>
<asp:Label ID="lblsuserid" runat="server" Text="ENTER USER ID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" style="margin-bottom: 0px"></asp:TextBox>
</p>
<asp:Label ID="lblspassword" runat="server" Text="ENTER PASSWORD"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<p>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" Width="66px" />
</p>
</form>
</body>
</html>
SIGN UP PAGE BUTTON CODE FOR ENTERING DATA INTO SQL SERVER DATABASE ON BUTTON CLICK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using middlelayer;
namespace WebApplication4
{
public partial class sign_up : System.Web.UI.Page
{
string conString = ConfigurationManager.ConnectionStrings["DBcon"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
string ins= "Insert into [LOGINDETAILS](USERID, PASSWORD) VALUES ('" +TextBox1.Text+ "' , '" +TextBox2.Text+ "')";
SqlCommand com = new SqlCommand(ins,con);
DataSet du = new DataSet();
SqlDataAdapter sdi = new SqlDataAdapter(com);
sdi.Fill(du);
con.Close();
}
}
}
I AM getting error in this last code only of sign up button it is not able to insert values of SIGN UP webform Textbox to sql server databse table and also not reflecting the real values which I want to add in sql server TABLE using sign up webform and also noty saving it. It is sending some error values . kindly help me with this.
BELOW ARE THE IMAGES OF LOG IN AS WELL AS SIGN UP PAGE FOR REFERENCE
LOGIN PAGE WEB FORM
SIGN UP PAGE WEBFORM
KINDLY HELP IN RESOLVING THIS ISSUE
Try this:
SqlConnection con = new SqlConnection(conString);
con.Open();
string ins= "Insert into [LOGINDETAILS](USERID, PASSWORD) VALUES (#param1 , #param2)";
SqlCommand cmd = new SqlCommand(ins,con);
cmd.Parameters.Add("#param1", SqlDbType.Varchar, 50).value = TextBox1.Text;
cmd.Parameters.Add("#param2", SqlDbType.Varchar, 50).value = TextBox2.Text;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
con.Close()
When trying to register to my database I am receiving the "The name 'UName' does not exist in the current context" error.
Register.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration Page</title>
</head>
<body>
<p>This is the registration page</p>
Home | Register
<form id="form1" runat="server">
<div>
<p>Enter First Name :</p>
<p>
<asp:TextBox ID="UName" runat="server" Width="271px"></asp:TextBox>
</p>
<p>
<asp:Button ID="registerButton" runat="server" Text="REGISTER" OnClick="registerEventMethod" />
</p>
</div>
</form>
</body>
</html>
Register.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Register : System.Web.UI.Page
{
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
String queryStr;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void registerEventMethod(object sender, EventArgs e)
{
registerUser();
}
private void registerUser()
{
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
conn.Open();
queryStr = "";
queryStr = "INSERT INTO jamieobr_obecarrentals.users (Forename)" +
"VALUES('" + UName.Text + "')";
cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
cmd.ExecuteReader();
conn.Close();
}
}
why am I getting this error? I have tried several solutions and all failed.
So I solved my own issue, the first initial issue was that I tried copying the .aspx file into a new solution, however this did not copy along the .aspx.designer.cs file therefore causing the problem.
However after trying to re write a fresh version manually which had a designer file with it I forgot to include the .cs file into the namespace of my solution therefore then generating a new problem.
However after including the .cs file into the namespace, hey presto, it worked!
I have asp.net web form and when Im trying to assing onclick event to a button I get following error:
Compiler Error Message: CS1061: 'ASP.webform1_aspx' does not contain a definition for 'Button1_Click' and no extension method 'Button1_Click' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 19: Line 20: Line 21:
Line 22:
Line 23:
ASP code is following:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="Form1" runat="server" method="post">
<div class="page">
<p>Persons</p>
<asp:Literal id="drpdwn" runat="server" />
<p>TransactionType</p>
<select id="sel" runat="server">
<option>bilance </option>
<option>liekākais parādnieks un aizdevējs</option>
<option>vidējais aizņēmuma lielums</option>
</select>
<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click" />
<table id="HTMLTable" width="300px;" runat="server">
<tr>
<td>
<b></b>
</td>
</tr>
</table>
</div>
</form>
</body>
<script type="text/javascript" >
var yourSelect = document.getElementById("sel");
var asdasd = yourSelect.options[yourSelect.selectedIndex].value;
</script>
</html>
And Codebehind is following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//int selectedIndex = (sel as HtmlSelect).SelectedIndex;
sel.Value.ToString();
SqlConnection cnn = new SqlConnection();
SqlDataReader rdr = null;
SqlCommand command = new SqlCommand();
cnn.ConnectionString = #"Server=localhost;Database=TildeTest;uid=AdminUser;pwd=AdminPwd;app=WebApplication1;";
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string CommandText = "select * from persons";
command = new SqlCommand(CommandText);
command.CommandType = CommandType.Text;
//command.Connection = cnn;
try
{
cnn.Open();
command.Connection = cnn;
rdr = command.ExecuteReader();
if (rdr.HasRows)
{
drpdwn.Text = "<select>";
drpdwn.Text += "<option> </option>";
while (rdr.Read())
{
drpdwn.Text += "<option>" + rdr.GetString(1) + "</option>";
}
drpdwn.Text += "</select>";
}
else
{
Console.WriteLine("No rows found.");
}
rdr.Close();
}
catch (Exception ex)
{
Console.WriteLine(e.ToString());
}
finally
{
if (cnn.State == ConnectionState.Open)
cnn.Close();
}
}
void Button1_Click(Object sender,
EventArgs e)
{
// do something
}
}
}
you can change void Button1_Click to protected void Button1_Click and try.
Assuming you are using visual studio, double click the button from design view, then write the code behind inside the generated function. That should work.
I have a stored procedure named "Graph" that should get a value to the parameter #Material, and I created a report in ASP.NET that should show a chart using the data from the stored procedure.
However, when I try to load the report I get:
An error has occurred during report processing.
Cannot create a connection to data source 'PhilipsMaterialsDataSet'.
ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetData' that has no parameters.
I tried different solutions but none of them worked. Also, I'm not sure if I should declare the parameter in the ASP code.
( by the way, GetData is not recognized here because it has one parameter (#Material-from the stored procedure) and for some reason, it is called without any parameters )
The code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
public partial class StatisticsPage : System.Web.UI.Page
{
string Connectionstring = "server=(local)\\SQLEXPRESS;database=PhilipsMaterials;Integrated Security=SSPI";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void btndisplay_Click(object sender, EventArgs e)
{
BindReport();
}
private void BindReport()
{
SSRSReport report = new SSRSReport();
SqlParameter[] sqlParams = new SqlParameter[] {
new SqlParameter("#Material","453567068441")
};
string ReportDataSource = "DataSet1";
bool bind = report.CreateReport(Connectionstring, "graph", sqlParams, ref ReportViewer1, ReportDataSource);
if (bind)
{
ReportViewer1.Visible = true;
}
}
}
public class SSRSReport
{
public SSRSReport()
{
//
// TODO: Add constructor logic here
//
}
public bool CreateReport(String Connectionstring,string StoreProcedureName ,SqlParameter[] Parameter,ref Microsoft.Reporting.WebForms.ReportViewer ReportViewer,string ReportDataSource)
{
bool reportbind = false;
using (SqlConnection con = new SqlConnection(Connectionstring))
{
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = StoreProcedureName;
com.Parameters.AddRange(Parameter);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(ds);
ReportDataSource datasource = new ReportDataSource(ReportDataSource, ds.Tables[0]);
if ( ds.Tables[0].Rows.Count > 0)
{
ReportViewer.LocalReport.DataSources.Clear();
ReportViewer.LocalReport.DataSources.Add(datasource);
//This is another solution I tried:
//List<ReportParameter> lstReportParameters = new List<ReportParameter>();
//ReportParameter objReportParameter = new ReportParameter("Material", "453567068441");
//lstReportParameters.Add(objReportParameter);
//ReportViewer.LocalReport.SetParameters(lstReportParameters);
// ReportViewer.ServerReport.Refresh();
reportbind = true;
}
}
return reportbind;
}
}
The ASP code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="StatisticsPage.aspx.cs" Inherits="StatisticsPage" %>
<%# Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test SSRS</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="610px" Width="1179px" ShowParameterPrompts="true">
<LocalReport ReportPath="Report.rdlc" >
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="PhilipsMaterialsDataSetTableAdapters.GraphTableAdapter" >
</asp:ObjectDataSource>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</form>
</body>
</html>
public DataSet CreateReport(String Connectionstring,string StoreProcedureName ,SqlParameter[] Parameter,ref Microsoft.Reporting.WebForms.ReportViewer ReportViewer,string ReportDataSource) {
//return the dataset
}
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="CreateReport" TypeName="SqlHelper" />
can u try to change ur method return value to DataSet..
and in the codebehind try to databind to that method..
Maybe it might work..
I have a stored procedure named "Graph" that should get a value to the parameter #Material, and I created a report in ASP.NET that should show a chart using the data from the stored procedure.
However, when I try to load the report I get:
"Data is unavailable"
Meaning, the parameter is not set correctly (with default value it works...)
The code-behind:
public partial class StatisticsPage : Page
{
string Connectionstring = "server=(local)\\SQLEXPRESS;database=PhilipsMaterials;Integrated Security=SSPI";
protected void btndisplay_Click(object sender, EventArgs e)
{
BindReport();
}
private void BindReport()
{
SSRSReport report = new SSRSReport();
SqlParameter[] sqlParams = new SqlParameter[] {
new SqlParameter("#Material","453567068441") };
string ReportDataSource = "DataSet1";
bool bind = report.CreateReport(Connectionstring, "graph", sqlParams, ref ReportViewer1, ReportDataSource);
if (bind)
{
ReportViewer1.Visible = true;
}
}
}
public class SSRSReport
{
public bool CreateReport(String Connectionstring, string StoreProcedureName , SqlParameter[] parameters, ref Microsoft.Reporting.WebForms.ReportViewer ReportViewer, string ReportDataSource)
{
bool reportbind = false;
using (SqlConnection con = new SqlConnection(Connectionstring))
{
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = StoreProcedureName;
com.Parameters.AddRange(parameters);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(ds);
ReportDataSource datasource = new ReportDataSource(ReportDataSource, ds.Tables[0]);
if ( ds.Tables[0].Rows.Count > 0)
{
ReportViewer.LocalReport.DataSources.Clear();
ReportViewer.LocalReport.DataSources.Add(datasource);
ReportParameter myParam = new ReportParameter("Material", "453567068441");
ReportViewer.LocalReport.SetParameters(myParam);
ReportViewer.ServerReport.Refresh();
reportbind = true;
}
}
return reportbind;
}
}
The markup:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="StatisticsPage.aspx.cs" Inherits="StatisticsPage" %>
<%# Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test SSRS</title>
</head>
<body>
<form id="form1" runat="server">
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="610px" Width="1179px" ShowParameterPrompts="true">
<LocalReport ReportPath="Report.rdlc" >
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="PhilipsMaterialsDataSetTableAdapters.GraphTableAdapter" >
<SelectParameters>
<asp:Parameter Name="Material"/>
</SelectParameters>
</asp:ObjectDataSource>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</form>
</body>
</html>
If the error occurs without a default parameter, then the issue is that an <asp:parameter> does not supply a value unless you provide one. You can set the DefaultValue property from markup or code, which this value is passed directly to the backend. You can also switch to the ControlParameter, SessionParameter, etc. which pulls the value from somewhere else.