but when ran the example and i click on the submit button I recieve the above error
I suppect this line
SearchValue[0] = new SqlParameter("@CategoryName",SqlDbType.NVarChar,15); <<<
--------------------------------------------------------------
protected void Button1_Click(object sender, EventArgs e)
{
//ReportViewer1.Visible is set to false in design mode
ReportViewer1.Visible = true;
SqlConnection thisConnection = new SqlConnection(thisConnectionString);
System.Data.DataSet thisDataSet = new System.Data.DataSet();
SearchValue[0] = new SqlParameter("@CategoryName",SqlDbType.NVarChar,15);
//db.AddOutParameter(cmd, "ProductName", DbType.String, 50);
// DropDownList1.SelectedValue);
/* Put the stored procedure result into a dataset */
thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", SearchValue);
/*or thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", dropdownlist1.selectedvalue);
if you only have 1 input parameter */
/* Associate thisDataSet (now loaded with the stored
procedure result) with the ReportViewer datasource */
ReportDataSource datasource = new
ReportDataSource("DataSetProducts_ShowProductByCategory",
thisDataSet.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
if (thisDataSet.Tables[0].Rows.Count == 0)
{
Label1.Text = "Sorry, no products under this category!";
}
ReportViewer1.LocalReport.Refresh();
}
}
}
SqlParameter[] SearchValue= new SqlParameter[1];
SearchValue[0] = new SqlParameter("@CategoryName",SqlDbType.NVarChar,15);
//db.AddOutParameter(cmd, "ProductName", DbType.String, 50);
// DropDownList1.SelectedValue);
/* Put the stored procedure result into a dataset */
thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue);
protected void Button1_Click(object sender, EventArgs e)
{
//ReportViewer1.Visible is set to false in design mode
ReportViewer1.Visible = true;
SqlConnection thisConnection = new SqlConnection(thisConnectionString);
System.Data.DataSet thisDataSet = new System.Data.DataSet();
SqlParameter[] SearchValue = new SqlParameter[1];
SearchValue[0] = new SqlParameter("@CategoryName", SqlDbType.NVarChar, 15);
//db.AddOutParameter(cmd, "ProductName", DbType.String, 50);
// DropDownList1.SelectedValue);
/* Put the stored procedure result into a dataset */
thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue);
//db.AddOutParameter(cmd, "ProductName", DbType.String, 50);
// DropDownList1.SelectedValue);
/* Put the stored procedure result into a dataset */
thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", SearchValue);
/*or thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", dropdownlist1.selectedvalue);
if you only have 1 input parameter */
/* Associate thisDataSet (now loaded with the stored
procedure result) with the ReportViewer datasource */
ReportDataSource datasource = new
ReportDataSource("DataSetProducts_ShowProductByCategory",
thisDataSet.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
if (thisDataSet.Tables[0].Rows.Count == 0)
{
Label1.Text = "Sorry, no products under this category!";
}
ReportViewer1.LocalReport.Refresh();
}
}
}
thats seems to have cleared up the error!! i now get this error
Parameter count does not match Parameter Value count.
is is what the code should look like now or have i miss something?
protected void Button1_Click(object sender, EventArgs e)
{
//ReportViewer1.Visible is set to false in design mode
ReportViewer1.Visible = true;
SqlConnection thisConnection = new SqlConnection(thisConnectionString);
System.Data.DataSet thisDataSet = new System.Data.DataSet();
// DropDownList1.SelectedValue);
object[] objParams = { 0, new SqlParameter("@CategoryName", SqlDbType.NVarChar, 15) };
thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", objParams);
/* Put the stored procedure result into a dataset */
// thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue);
//db.AddOutParameter(cmd, "ProductName", DbType.String, 50);
// DropDownList1.SelectedValue);
/* Put the stored procedure result into a dataset */
thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", SearchValue);
/*or thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", dropdownlist1.selectedvalue);
if you only have 1 input parameter */
/* Associate thisDataSet (now loaded with the stored
procedure result) with the ReportViewer datasource */
ReportDataSource datasource = new
ReportDataSource("DataSetProducts_ShowProductByCategory",
thisDataSet.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
if (thisDataSet.Tables[0].Rows.Count == 0)
{
Label1.Text = "Sorry, no products under this category!";
}
ReportViewer1.LocalReport.Refresh();
}
}
}
SirReadAlot
Member
9 Points
23 Posts
Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 05:46 PM|LINK
Hi Friends,
I have followed this example
http://www.codeproject.com/Articles/15597/Using-the-ASP-NET-2-0-ReportViewer-in-Local-Mode?fid=341063&df=90&mpp=25&noise=3&prof=False&sort=Position&view=Quick&spc=Relaxed&fr=151#xx0xx
but when ran the example and i click on the submit button I recieve the above error
I suppect this line
SearchValue[0] = new SqlParameter("@CategoryName",SqlDbType.NVarChar,15); <<<
-------------------------------------------------------------- protected void Button1_Click(object sender, EventArgs e) { //ReportViewer1.Visible is set to false in design mode ReportViewer1.Visible = true; SqlConnection thisConnection = new SqlConnection(thisConnectionString); System.Data.DataSet thisDataSet = new System.Data.DataSet(); SearchValue[0] = new SqlParameter("@CategoryName",SqlDbType.NVarChar,15); //db.AddOutParameter(cmd, "ProductName", DbType.String, 50); // DropDownList1.SelectedValue); /* Put the stored procedure result into a dataset */ thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue); /*or thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", dropdownlist1.selectedvalue); if you only have 1 input parameter */ /* Associate thisDataSet (now loaded with the stored procedure result) with the ReportViewer datasource */ ReportDataSource datasource = new ReportDataSource("DataSetProducts_ShowProductByCategory", thisDataSet.Tables[0]); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(datasource); if (thisDataSet.Tables[0].Rows.Count == 0) { Label1.Text = "Sorry, no products under this category!"; } ReportViewer1.LocalReport.Refresh(); } } }RameshRajend...
Star
7983 Points
2099 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 05:50 PM|LINK
try this
earchValue[0] =Convert.ToString( new SqlParameter("@CategoryName",SqlDbType.NVarChar,15));
SirReadAlot
Member
9 Points
23 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:08 PM|LINK
Hi Ramesh,
Thanks for the post! I have tried the code but got this error
Error 1 Cannot implicitly convert type 'string' to 'System.Data.SqlClient.SqlParameter'
RameshRajend...
Star
7983 Points
2099 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:14 PM|LINK
Oh
ok just sorry for my above code
Please try again
SqlParameter[] SearchValue= new SqlParameter[1]; SearchValue[0] = new SqlParameter("@CategoryName",SqlDbType.NVarChar,15); //db.AddOutParameter(cmd, "ProductName", DbType.String, 50); // DropDownList1.SelectedValue); /* Put the stored procedure result into a dataset */ thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue);SirReadAlot
Member
9 Points
23 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:19 PM|LINK
opps, did not work.. see my full code
protected void Button1_Click(object sender, EventArgs e) { //ReportViewer1.Visible is set to false in design mode ReportViewer1.Visible = true; SqlConnection thisConnection = new SqlConnection(thisConnectionString); System.Data.DataSet thisDataSet = new System.Data.DataSet(); SqlParameter[] SearchValue = new SqlParameter[1]; SearchValue[0] = new SqlParameter("@CategoryName", SqlDbType.NVarChar, 15); //db.AddOutParameter(cmd, "ProductName", DbType.String, 50); // DropDownList1.SelectedValue); /* Put the stored procedure result into a dataset */ thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue); //db.AddOutParameter(cmd, "ProductName", DbType.String, 50); // DropDownList1.SelectedValue); /* Put the stored procedure result into a dataset */ thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue); /*or thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", dropdownlist1.selectedvalue); if you only have 1 input parameter */ /* Associate thisDataSet (now loaded with the stored procedure result) with the ReportViewer datasource */ ReportDataSource datasource = new ReportDataSource("DataSetProducts_ShowProductByCategory", thisDataSet.Tables[0]); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(datasource); if (thisDataSet.Tables[0].Rows.Count == 0) { Label1.Text = "Sorry, no products under this category!"; } ReportViewer1.LocalReport.Refresh(); } } }RameshRajend...
Star
7983 Points
2099 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:21 PM|LINK
Now what error get you???
SirReadAlot
Member
9 Points
23 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:23 PM|LINK
same as before
Failed to convert parameter value from a SqlParameter to a String.
RameshRajend...
Star
7983 Points
2099 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:35 PM|LINK
The problem is SearchValue[0] .What mean SearchValue[0]????
change that
object[] objParams = { 0,new SqlParameter("@CategoryName",SqlDbType.NVarChar,15)}; thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory",objParams );Please refer this
http://www.codeproject.com/Articles/15666/Data-Access-Application-Block-NET-2-0-Get-Return-V
SirReadAlot
Member
9 Points
23 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:42 PM|LINK
hi,
thats seems to have cleared up the error!! i now get this error
Parameter count does not match Parameter Value count.
is is what the code should look like now or have i miss something?
protected void Button1_Click(object sender, EventArgs e) { //ReportViewer1.Visible is set to false in design mode ReportViewer1.Visible = true; SqlConnection thisConnection = new SqlConnection(thisConnectionString); System.Data.DataSet thisDataSet = new System.Data.DataSet(); // DropDownList1.SelectedValue); object[] objParams = { 0, new SqlParameter("@CategoryName", SqlDbType.NVarChar, 15) }; thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", objParams); /* Put the stored procedure result into a dataset */ // thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue); //db.AddOutParameter(cmd, "ProductName", DbType.String, 50); // DropDownList1.SelectedValue); /* Put the stored procedure result into a dataset */ thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue); /*or thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", dropdownlist1.selectedvalue); if you only have 1 input parameter */ /* Associate thisDataSet (now loaded with the stored procedure result) with the ReportViewer datasource */ ReportDataSource datasource = new ReportDataSource("DataSetProducts_ShowProductByCategory", thisDataSet.Tables[0]); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(datasource); if (thisDataSet.Tables[0].Rows.Count == 0) { Label1.Text = "Sorry, no products under this category!"; } ReportViewer1.LocalReport.Refresh(); } } }RameshRajend...
Star
7983 Points
2099 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 15, 2012 06:55 PM|LINK
look it
http://forums.asp.net/t/917592.aspx/1
http://forums.asp.net/t/1304883.aspx/1