--试试将存储过程改成这样:CREATE PROCEDURE SearchPhone @lastname varchar(10)='%', @fristname varchar(10)='%', @Price1 varchar(20), @Price2 varchar(20), @Introduce1 varchar(20), @introduce2 varchar(20), @Catagroy varchar(20) AS select phonename from Mobilephone where (introduce like @lastname+@introduce1+@fristname) and (introduce like @lastname+@introduce2+@fristname) and price in( select price from Mobilephone where (price>=@price1 and price<=@price2) and catagroy in( select catagroy from Mobilephone where catagroy =@catagroy ) ) GO
CREATE PROCEDURE SearchPhone @lastname varchar(10)='%', @fristname varchar(10)='%', @Price1 varchar(20), @Price2 varchar(20), @Introduce1 varchar(20), @introduce2 varchar(20), @Catagroy varchar(20)='全部品牌' AS select phonename from Mobilephone where (introduce like @lastname+@introduce1+@fristname) and (introduce like @lastname+@introduce2+@fristname) and price in( select price from Mobilephone where (price>=@price1 and price<=@price2) and catagroy in( select catagroy from Mobilephone where @catagroy='全部品牌' or catagroy =@catagroy ) )
CREATE PROCEDURE SearchPhone @lastname varchar(10)='%', @fristname varchar(10)='%', @Price1 varchar(20), @Price2 varchar(20), @Introduce1 varchar(20), @introduce2 varchar(20), @Catagroy varchar(20)='全部品牌' AS select phonename from Mobilephone where (introduce like @lastname+@introduce1+@fristname) and (introduce like @lastname+@introduce2+@fristname) and price in( select price from Mobilephone where (price>=@price1 and price<=@price2) and catagroy='全部品牌' or catagroy in( select catagroy from Mobilephone where catagroy =@catagroy ) )
public DataSet GetList(int price1,int price2,string catagroy,string introduce1,string introduce2)
{
Database data=new Database();
DataSet dataSet = new DataSet();
SqlParameter[] prams = {
data.MakeInParam("@price1", SqlDbType.VarChar, 20, price1),
data.MakeInParam("@price2", SqlDbType.VarChar, 20, price2),
data.MakeInParam("@catagroy", SqlDbType.VarChar, 20, catagroy),
data.MakeInParam("@introduce1", SqlDbType.VarChar, 20, introduce1),
data.MakeInParam("@introduce2", SqlDbType.VarChar, 20, introduce2),
};
dataSet=(DataSet)data.RunProcedure("SearchPhone",prams,"SearchPhone");
return(dataSet);
}
这是表示层:
private void Button1_Click(object sender, System.EventArgs e)
{
components.SearchPhone searchphone=new go68.components.SearchPhone();
int price1=1000,price2=6000;
string catagroy=DropDownList2.SelectedItem.Text.Trim();
string introduce1=RadioButtonList1.SelectedItem.Text.Trim();
string introduce2=RadioButtonList2.SelectedItem.Text.Substring(0,2);
DataSet ds=searchphone.GetList(price1,price2,catagroy,introduce1,introduce2);
DataTable dt=ds.Tables["SearchPhone"];
DataRow dr=dt.Rows[0]; }
调试后显示dr为空的
@lastname varchar(10)='%',
@fristname varchar(10)='%',
@Price1 varchar(20),
@Price2 varchar(20),
@Introduce1 varchar(20),
@introduce2 varchar(20),
@Catagroy varchar(20)
AS
select phonename
from Mobilephone
where (introduce like @lastname+@introduce1+@fristname)
and (introduce like @lastname+@introduce2+@fristname)
and price in(
select price
from Mobilephone
where (price>=@price1 and price<=@price2)
and catagroy in(
select catagroy
from Mobilephone
where catagroy =@catagroy
)
)
GO
谢谢
@lastname varchar(10)='%',
@fristname varchar(10)='%',
@Price1 varchar(20),
@Price2 varchar(20),
@Introduce1 varchar(20),
@introduce2 varchar(20),
@Catagroy varchar(20)='全部品牌'
AS
select phonename
from Mobilephone
where (introduce like @lastname+@introduce1+@fristname)
and (introduce like @lastname+@introduce2+@fristname)
and price in(
select price
from Mobilephone
where (price>=@price1 and price<=@price2)
and catagroy in(
select catagroy
from Mobilephone
where @catagroy='全部品牌'
or catagroy =@catagroy
)
)
CREATE PROCEDURE SearchPhone
@lastname varchar(10)='%',
@fristname varchar(10)='%',
@Price1 varchar(20),
@Price2 varchar(20),
@Introduce1 varchar(20),
@introduce2 varchar(20),
@Catagroy varchar(20)='全部品牌'
AS
select phonename
from Mobilephone
where (introduce like @lastname+@introduce1+@fristname)
and (introduce like @lastname+@introduce2+@fristname)
and price in(
select price
from Mobilephone
where (price>=@price1 and price<=@price2)
and catagroy='全部品牌' or catagroy in(
select catagroy
from Mobilephone
where catagroy =@catagroy
)
)