在存储过程中创建一临时表,前台调用查询找不到该临时表!

KLL KLL 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在存储过程中如:
create proc Aa
@age int
as
if object_id('tempdb.dbo.##test') is null
begin
create table tempdb.dbo.##test
(
age int not null,
num int not null
)
insert into ##test values(1,1)
end
else
begin
update ##test set age=@age
end
go

create proc getTest
as
select * from ##test

我是想在前台asp.net中,有一文本框,和一按钮,和一gridview,当点击按钮时,就执行那两个proc,
同时显示数据到gridview中.

表示层后台代码:
protected void Button1_Click(object sender, EventArgs e)
{
int age =Convert.ToInt32(TextBox2.Text.Trim());
DBDAQDateManager.test(age);

GridView2.DataSource = DBDAQDateManager.getTest();
GridView2.DataBind();
}
一运行就出现对象名'.##test'无效.
然而在运行之前,先执行存储过程中的
create table tempdb.dbo.##test

age int not null,
num int not null
)
insert into ##test values(1,1)
再运行好好的。

还有就是在数据库运行也是好好的。把SQL服务断开连接,再连接。这时临时表消失。
再在SQL中执行
exec Aa 2
exec getTest
这能行好好的,再运行程序也是好好的。

我就是想到程序中运行,并判断是否有临时表,无的话就创建添加,有的话就更新。
可就是一运行就报那错。
对象名'##test'无效.
...全文

相关推荐

评论 37
收藏 已收藏
分享
返回顶部
KLL
.NET社区 62,275 成员 668,967 内容