create procedure GetOtherVotes
@id int
as
select id,question,
isnull((select sum(vote_num) from [Option] where vote_id=Vote.id),0)
as total_count,
start_date,end_date,type,active
from Vote where id<>@id and getdate()<end_date and getdate()>start_date
go
use TouPiao
select id,question,start_date,end_date,
isnull((select sum(vote_num) from [Option] where vote_id=Vote.id),0) as total_count,
start_date,end_date
from Vote where id<>'1'上面的存储过程和SQL文本语句实现的是同一功能。可是绑定数据的时候为什么用存储过程的时候绑定不上数据啊。
绑定的代码如下:private void BindOtherVotes()
{
/*DAL.ExecuteProcedure exec = new DAL.ExecuteProcedure();
DataTable table = new DataTable();
SqlParameter[] parameters ={ new SqlParameter("@id",VoteID)};
int flag = exec.run(table,"GetOtherVotes",parameters);*/
DAL.ExecuteSql exec = new DAL.ExecuteSql();
DataTable table = new DataTable();
string sqltext = "select id,question,start_date,end_date,isnull((select sum(vote_num) from [Option] where vote_id=Vote.id),0) as total_count,start_date,end_date from Vote where id<>'"+VoteID+"'";
int flag = exec.run(table,sqltext);
if (flag == 1)
{
dgOtherVotes.DataSource = table.DefaultView;
dgOtherVotes.DataBind();
}
else
{
Response.Write(exec.ErroeMessage);
}
}去掉注销部分的存储过程绑定后,是对的,可是用注销部分的存储过程绑定的时候没有错误,但是DataGrid上面没有任何的数据。
在查询分析器执行看下有没结果
运行没错的话再跟踪调试。