我正在开发一个运行存储过程的简单搜索页面,但我不断收到此错误:
过程 getSearch 没有提供参数和参数。
这是我的存储过程:
ALTER PROCEDURE [dbo].[getSearch]
AS
BEGIN
Declare @ProjectCode varchar;
SELECT [name],[address],[results]
FROM [myTb]
WHERE [name] like '%' + @ProjectCode + '%'
ORDER BY [name] ASC
END
...这是我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDbConnectionString1"].ToString()))
{
using (SqlCommand command = new SqlCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "getSearch";
command.Connection = connection;
command.Parameters.AddWithValue("@ProjectCode", TbProjectCode.Text);
connection.Open();
SqlDataAdapter a = new SqlDataAdapter(command);
a.Fill(ds);
}
}
gvResults.DataSource = ds;
gvResults.DataBind();
}
该设计:
<div style="width: 375px; height: 66px">
<asp:TextBox ID="TbProjectCode" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Search" /><br />
</div>
<div>
<asp:GridView ID="gvResults" runat="server" Width="718px"></asp:GridView>
</div>
我可以就我的存储过程的问题获得一些帮助吗?我正在按照上一篇文章中的示例进行操作,但是,我仍然收到此错误。