在存储过程中创建一临时表,前台调用查询找不到该临时表!
在存储过程中如:
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'无效.
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'无效.
...全文
相关推荐
存储过程中的临时表使用方法
创建临时表。临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。
掌握Oracle存储过程与临时表的应用
在数据库管理系统中,临时表是一种特殊类型的表,它为特定的数据库会话或事务提供存储空间来存储临时数据。了解临时表的定义及其生命周期对于数据库管理员和开发人员来说至关重要,因为临时表可以帮助他们有效地管理临时数据,提高查询性能,并简化应用程序逻辑。在本章节中,我们将详细探讨临时表的概念以及它们在数据库系统中的存在周期。临时表是一种为特定会话或事务提供临时存储的数据库对象。它们与永久表的主要区别在于,临时表不存储在数据库的数据文件中,而是存储在内存中或者临时段(tempfile)中。
mysql临时表用法分析【查询结果可存在临时表中】
主要介绍了mysql临时表用法,结合实例形式分析了MySQL将查询结果存储在临时表中的相关操作技巧,需要的朋友可以参考下
Oracle存储过程中使用临时表
Oracle存储过程中使用临时表 会话级临时表 事务级临时表
MySQL中临时表的基本创建与使用教程
主要介绍了MySQL中临时表的基本创建与使用教程,注意临时表中数据的清空问题,需要的朋友可以参考下


