I honestly have never used SqlHelper.ExecuteDataset method so I was assuming it behaves like other execute methods in ADO.net. Sorry for the confusion.
Can you kindly give this a try?
SqlConnection thisConnection = new SqlConnection(thisConnectionString);
System.Data.DataSet thisDataSet = new System.Data.DataSet();
SqlCommand sqlCom = new SqlCommand("ShowProductByCategory", thisConnection);
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem;
SqlDataAdapter dadapter = new SqlDataAdapter();
dadapter.SelectCommand = sqlCom;
dadapter.Fill(thisDataSet);
I honestly have never used SqlHelper.ExecuteDataset method so I was assuming it behaves like other execute methods in ADO.net. Sorry for the confusion.
Can you kindly give this a try?
SqlConnection thisConnection = new SqlConnection(thisConnectionString);
System.Data.DataSet thisDataSet = new System.Data.DataSet();
SqlCommand sqlCom = new SqlCommand("ShowProductByCategory", thisConnection);
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem;
SqlDataAdapter dadapter = new SqlDataAdapter();
dadapter.SelectCommand = sqlCom;
dadapter.Fill(thisDataSet);
Ruchira was good.
I already give some links in this way.But u not solve that.But Use ruchira answer.its good
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();
SqlCommand sqlCom = new SqlCommand("ShowProductByCategory", thisConnection);
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value = DropDownList1.SelectedValue;
SqlDataAdapter dadapter = new SqlDataAdapter();
dadapter.SelectCommand = sqlCom;
dadapter.Fill(thisDataSet);
/*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("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();
}
}
}
Ruchira
All-Star
43068 Points
7045 Posts
MVP
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 16, 2012 12:58 PM|LINK
Hi,
I honestly have never used SqlHelper.ExecuteDataset method so I was assuming it behaves like other execute methods in ADO.net. Sorry for the confusion.
Can you kindly give this a try?
SqlConnection thisConnection = new SqlConnection(thisConnectionString); System.Data.DataSet thisDataSet = new System.Data.DataSet(); SqlCommand sqlCom = new SqlCommand("ShowProductByCategory", thisConnection); sqlCom.CommandType = CommandType.StoredProcedure; sqlCom.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem; SqlDataAdapter dadapter = new SqlDataAdapter(); dadapter.SelectCommand = sqlCom; dadapter.Fill(thisDataSet);
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.RameshRajend...
Star
7983 Points
2099 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 16, 2012 01:05 PM|LINK
Ruchira was good.
I already give some links in this way.But u not solve that.But Use ruchira answer.its good
http://codingboys.blogspot.in/2012/05/stored-procedure-in-sql-with-simple.html
http://forums.asp.net/t/1577724.aspx/1
SirReadAlot
Member
9 Points
23 Posts
Re: Failed to convert parameter value from a SqlParameter to a String.
Dec 16, 2012 01:40 PM|LINK
thanks Ruchaira and Resh
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(); SqlCommand sqlCom = new SqlCommand("ShowProductByCategory", thisConnection); sqlCom.CommandType = CommandType.StoredProcedure; sqlCom.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value = DropDownList1.SelectedValue; SqlDataAdapter dadapter = new SqlDataAdapter(); dadapter.SelectCommand = sqlCom; dadapter.Fill(thisDataSet); /*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("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(); } } }