c# 调用存储过程??

june17 2009-06-15 06:43:15
我建了一个存储过程,是为了搜索功能而建的,sql语句是这样的:

CREATE PROCEDURE UP_SearchHouseInfo

@hifangwulx nvarchar(500),
@hihuxing nvarchar(500),
@hifangyuanqy nvarchar(500),
@hinidingjg nvarchar(500),
@SearchKey varchar(100)=null
AS

Select * from mp_HouseInfo
where hifangwulx=@hifangwulx and hihuxing=@hihuxing and hifangyuanqy=@hifangyuanqy
and hinidingjg =@hinidingjg
and hifangyuanmc like '%'+rtrim(@SearchKey)+'%'
or hifangyuandd like '%'+rtrim(@SearchKey)+'%'
or hijianzhumj like '%'+rtrim(@SearchKey)+'%'
or hichangquangs like '%'+rtrim(@SearchKey)+'%'
or hijianzhund like '%'+rtrim(@SearchKey)+'%'
or hilianxir like '%'+rtrim(@SearchKey)+'%'
or hidianhua like '%'+rtrim(@SearchKey)+'%'
or hibuchongshm like '%'+rtrim(@SearchKey)+'%'
or hiimage like '%'+rtrim(@SearchKey)+'%'

GO

然后我在后台用了c#来调用这个存储过程:
代码如下:
 private void DataListBind()
{

string strconn = "server=.;database=Mojo_tianzhuju;uid=sa;pwd=p@ssw0rd";
SqlConnection Conn = new SqlConnection(strconn);
Conn.Open();
string sKey = this.Txtproduct.Text;
SqlDataAdapter sda = new SqlDataAdapter();
//调用存储过程
SqlCommand comm = new SqlCommand("EXEC UP_SearchHouseInfo", Conn);
comm.CommandType = CommandType.StoredProcedure;
if (this.RadioButton1.Checked)
rbtleixing = "租房";
else if (this.RadioButton2.Checked)
rbtleixing = "二手房";
else if (this.RadioButton3.Checked)
rbtleixing = "新房";
else if (this.RadioButton4.Checked)
rbtleixing = "商用房";
comm.Parameters.Add(new SqlParameter("@hifangwulx", rbtleixing));
comm.Parameters.Add(new SqlParameter("@hihuxing",this.Shi.SelectedValue+"室"+this.Ting.SelectedValue+"厅"+this.Wei.SelectedValue+"卫"));
comm.Parameters.Add(new SqlParameter("@hifangyuanqy", this.quyu.SelectedValue));
comm.Parameters.Add(new SqlParameter("@hinidingjg", this.shoujia.SelectedValue));
comm.Parameters.Add(new SqlParameter("@SearchKey",sKey));

DataSet ds = new DataSet();
comm.CommandTimeout = 999;
sda.SelectCommand = comm;
DataListHouseInfo.DataSource = ds;
DataListHouseInfo.DataBind();



}

可是运行到DataListHouseInfo.DataBind();
这个语句时就出现了错误,
各位大侠可以给点建议不?


...全文
35 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
weijianliang 2009-07-15
  • 打赏
  • 举报
回复
学习了。
june17 2009-06-16
  • 打赏
  • 举报
回复
呵呵,谢谢10楼,可以了,谢谢。昨天还一直在那里担心,真好 ^-^
ljhcy99 2009-06-16
  • 打赏
  • 举报
回复
ds 没有填充。
public_private 2009-06-16
  • 打赏
  • 举报
回复
还真是强呀,佩服!
修改一下昵称 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 june17 的回复:]
呵呵,谢谢楼上的那位,刚好,我也想到了。
不过加上这句代码,就在这里又出现了错误。
说是找不到那个存储过程,
这么看来,应该是存储过程那里有问题吧??
[/Quote]
SqlCommand comm = new SqlCommand("EXEC UP_SearchHouseInfo", Conn);
SqlCommand comm = new SqlCommand("UP_SearchHouseInfo", Conn);
june17 2009-06-15
  • 打赏
  • 举报
回复
呵呵,谢谢楼上的那位,刚好,我也想到了。
不过加上这句代码,就在这里又出现了错误。
说是找不到那个存储过程,
这么看来,应该是存储过程那里有问题吧??
阿牛138588 2009-06-15
  • 打赏
  • 举报
回复
参数类型 没有指定
阿牛138588 2009-06-15
  • 打赏
  • 举报
回复
参数类型

建议使用SqlCommandBuild.Diliver一下,然后

sda.Parameters["@hifangwulx"]= rbtleixing;
就可以解决问题了
pwf8285319 2009-06-15
  • 打赏
  • 举报
回复
LZ 没看见 我再给指指
多了一句sda.Fill(ds); //填充dataset
修改一下昵称 2009-06-15
  • 打赏
  • 举报
回复
估计就是这条SQL语句的问题,你先测试一下你的这句SQL语句是否查询到了数据;
Select * from mp_HouseInfo
where hifangwulx=@hifangwulx and hihuxing=@hihuxing and hifangyuanqy=@hifangyuanqy
and hinidingjg =@hinidingjg
and hifangyuanmc like '%'+rtrim(@SearchKey)+'%'
or hifangyuandd like '%'+rtrim(@SearchKey)+'%'
or hijianzhumj like '%'+rtrim(@SearchKey)+'%'
or hichangquangs like '%'+rtrim(@SearchKey)+'%'
or hijianzhund like '%'+rtrim(@SearchKey)+'%'
or hilianxir like '%'+rtrim(@SearchKey)+'%'
or hidianhua like '%'+rtrim(@SearchKey)+'%'
or hibuchongshm like '%'+rtrim(@SearchKey)+'%'
or hiimage like '%'+rtrim(@SearchKey)+'%'
june17 2009-06-15
  • 打赏
  • 举报
回复
兄台,你引用我的函数是什么意思?
给点指示吧,我实在不是很熟。
谢谢谢谢。
你的那眼睛真的够让人寒的。
june17 2009-06-15
  • 打赏
  • 举报
回复
恩,就是这个问题,
可是哪里出现问题了?是我建的存储过程就有问题呢,还是代码的问题?

楼上的,你的图案也吓人了点,搞的人心里都寒
  • 打赏
  • 举报
回复

string strconn = "server=.;database=Mojo_tianzhuju;uid=sa;pwd=p@ssw0rd";
SqlConnection Conn = new SqlConnection(strconn);
Conn.Open();
string sKey = this.Txtproduct.Text;

//调用存储过程
SqlDataAdapter sda= new SqlDataAdapter("EXEC UP_SearchHouseInfo", Conn);
comm.CommandType = CommandType.StoredProcedure;
if (this.RadioButton1.Checked)
rbtleixing = "租房";
else if (this.RadioButton2.Checked)
rbtleixing = "二手房";
else if (this.RadioButton3.Checked)
rbtleixing = "新房";
else if (this.RadioButton4.Checked)
rbtleixing = "商用房";
sda.Parameters.Add(new SqlParameter("@hifangwulx", rbtleixing));
sda.Parameters.Add(new SqlParameter("@hihuxing",this.Shi.SelectedValue+"室"+this.Ting.SelectedValue+"厅"+this.Wei.SelectedValue+"卫"));
sda.Parameters.Add(new SqlParameter("@hifangyuanqy", this.quyu.SelectedValue));
sda.Parameters.Add(new SqlParameter("@hinidingjg", this.shoujia.SelectedValue));
sda.Parameters.Add(new SqlParameter("@SearchKey",sKey));

DataSet ds = new DataSet();
comm.CommandTimeout = 999;
sda.Fill(ds);
DataListHouseInfo.DataSource = ds;
DataListHouseInfo.DataBind();


  • 打赏
  • 举报
回复
你的數據源為空 ds沒 負值

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧