【发布时间】:2016-01-01 21:07:57
【问题描述】:
当我通过 .net 调用带有参数的 SQL Server 存储过程时会发生这种情况,即使我提供了参数。
这是我的存储过程代码:
create procedure spGetCityByNames
@cityName char(10)
as
begin
select *
from tblCity
where cityName like @cityName + '%'
end
还有我的 .net 代码:
SqlCommand cmd = new SqlCommand("spGetCityByNames", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@cityName", TextBox1.Text + "%");
con.Open();
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
con.Close();
【问题讨论】:
-
欢迎来到 Stack Overflow。显示您的
spGetCountryByNames程序,而不是spGetCityByNames。 that 过程中的错误消息点。请阅读FAQ 和How to Ask 作为开始.. -
使用 varchar(10) 怎么样?
-
抱歉,我先在国家/地区尝试过,然后在城市中尝试过。。
-
错误消息:过程或函数“spGetCityByNames”需要参数“@cityName”,但未提供
-
我还检查了 spGetCityByNames 'd%' 是否返回 NULL,即使城市是用 'd' 字母列出的......为什么会这样??
标签: c# .net sql-server stored-procedures