因此,我尝试使用三层结构进行搜索,并且在线上没有很多好的示例,因此我尝试了一下以查看是否可以使它起作用,但由于某种原因它不会起作用。你能看一下我的代码,看看我在做什么错吗?
存储过程:
CREATE PROCEDURE [dbo].[GuestSearch]
@FirstName varchar(20),
@LastName varchar(20),
@Phone varchar(15)
AS
SELECT FirstName, Lastname, Phone
FROM Guest
WHERE FirstName LIKE '%'+@FirstName+'%'
AND LastName LIKE '%'+@LastName+'%' AND
Phone LIKE '%'+@Phone+'%'
BEL
public class GuestBEL
{
public int GuestID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
}
BLL
public DataSet FindGuest()
{
GuestDAL objDAL = new GuestDAL();
return objDAL.FindGuest();
}
DAL
public DataSet FindGuest()
{
DataSet dts = new DataSet();
SqlCommand cmd = new SqlCommand("GuestSearch", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
con.Open();
adapt.Fill(dts);
cmd.Dispose();
dts.Dispose();
con.Close();
return dts;
}
UI
protected void btnSearch_Click(object sender, EventArgs e)
{
DataSet data = new DataSet();
data = objBLL.FindGuest();
gvGuest.DataSource = data;
gvGuest.DataBind();
readGrid();
}
因此,当我在搜索中键入内容时,gridview应该显示我在文本框中输入的内容,但是由于某种原因,我得到的错误是“过程或函数“ GuestSearch”需要参数“ @FirstName”,而该参数不是提供。”
答案 0 :(得分:0)
您需要将参数添加到Command
函数中的public DataSet FindGuest()
:
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = "somename";
cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = "somelastname";
cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = "somephone";