Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedure 'pt3' expects parameter '@ptype', which was not supplied

Status
Not open for further replies.

sirisai

Programmer
Joined
Apr 13, 2004
Messages
2
Location
US
hi, I am trying to populate datalist with a dataset using parameterised procedure, here is my code

string str=Request.Params["producttype"];


SqlDataAdapter da=new SqlDataAdapter( "pt3",this.sqlConnection1);
da.SelectCommand.CommandType=CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(new SqlParameter("@ptype", SqlDbType.NVarChar,20));
da.SelectCommand.Parameters["@ptype"].Value=str;
DataSet ds= new DataSet();
this.sqlConnection1.Open();
da.Fill(ds,"product");
this.DataList1.DataSource=ds;
this.DataList1.DataBind();
and my procedure is
create procedure pt3
@ptype nvarchar(20)
as
select productcode, productname,productdescription,unitprice from product where producttype=@ptype
go

I don't know why is it giving me that exception. Please help me out with an answer.
 
how about trying

da.SelectCommand.Parameters[0].Value=str; ???
 
Rework the code try
{
this.sqlConnection1.Open();
SqlDataAdapter da=new SqlDataAdapter( "pt3",this.sqlConnection1);
da.SelectCommand.CommandType=CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(new SqlParameter("@ptype", SqlDbType.NVarChar,20));
da.SelectCommand.Parameters["@ptype"].Value=str;
DataSet ds= new DataSet();
da.Fill(ds,"product");
this.DataList1.DataSource=ds;
this.DataList1.DataBind();
}
catch (Exception ex)
{
string sMsg = ex.GetType() + ex.Message;
}
-obislavu-

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top