ASP.NET存储的程序 [英] ASP.NET Stored PRocedures

查看:58
本文介绍了ASP.NET存储的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 更改  procedure  VisitorDetails1 
@ p_name nvarchar 50 ),
< span class =code-sdkkeyword> @ p_City nvarchar 100 ),
@ p_Dept nvarchar (max),
@p_TableName nvarchar 50
as

IF EXISTS SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @ p_TableName))
- IF db_id('@ TabName')IS NOT NULL
- IF OBJECT_ID('@ TabName','U ')不为空
开始

声明 @ set nvarchar 50
set @set = ' insert into' + @p_TableName + ' (Name,City,Dept)值(@ p_name,@ p_City,@ p_Dept)'

- set @ set ='insert into'+ @ TableName +'值(@ name,@ City,@ Dept)'

exec @set
打印 ' 成功'
end
else
开始
print ' 表格不存在'
end





- 参数执行部分:

exec VisitorDetails1 Perumal,Chennai,IT,VSampleData - (这是我创建的表名)



执行结果后IS:



消息137,级别15,状态2,行1

必须声明标量变量@p_。

成功..



实际上我需要检查表是否已经存在..如果存在于同一个表中,则应该插入数据,否则它应该执行表不在这里。这些都应该是动态的..





请帮我看看我需要做什么..

谢谢Advace ,。

解决方案

首先,您要重新发布您的问题。你的一个问题的解决方案是这里 [ ^ ]。如果有其他疑问或澄清,您应该改进您的问题。其次,存储过程的流程应如下所示:

 更改  procedure  VisitorDetails1 
@ p_name nvarchar 50 ),
@ p_City nvarchar (< span class =code-digit> 100 ),
@ p_Dept nvarchar (max),
@ p_TableName nvarchar 50
as
BEGIN
< span class =code-keyword> IF ( EXISTS SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @ p_TableName))
BEGIN
- 声明@set nvarchar(50)
声明 @ set nvarchar 500
- - 将您的查询替换为
set @ set = ' 插入' + @ TableName + ' (Name,City,Dept)值(''' + @ name + ' '',''' + @ City + ' '',''' + @ Dept + ' '')'
打印 ' 成功'
END
其他
BEGIN
打印 表格不存在'
END
END


我想这句话应该是:



设置@set =''插入''+ @ TableName +''(Name,City,Dept)值(''''''+ @ name +' '''''''''''''+ @City +'''''''''''''+ @Dept +''''''''''


Alter procedure VisitorDetails1
@p_name nvarchar(50),
@p_City nvarchar(100),
@p_Dept nvarchar(max),
@p_TableName nvarchar(50)
as

IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=@p_TableName)) 
--IF db_id('@TabName') IS NOT NULL
--IF OBJECT_ID('@TabName','U') is not null
begin

Declare @set nvarchar(50)
set @set='insert into '+@p_TableName+'(Name,City,Dept) values(@p_name,@p_City,@p_Dept)'

--set @set='insert into '+@TableName+' values(@name,@City,@Dept)'

exec(@set)
Print 'Success'
end
else
begin
print 'Table is Not there'
end



--Parameters Execution Part:
exec VisitorDetails1 Perumal,Chennai,IT,VSampleData--(This Is Table Name I created)

After Executing Result IS:

Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@p_".
Success..

Actually I need to Check the table is already exist or not.. if exist in that same table the data should be inserted other wise it should execute Table is Not There. These all should dynamically..


Please Help Me what I need to Do..
Thanks Advace,.

解决方案

Firs, you are reposting your question. The solution to one of your problem is Here[^]. You should improve your question if there is additional doubt or clarification. Second, the flow of your stored procedure should go like this:

Alter procedure VisitorDetails1
@p_name nvarchar(50),
@p_City nvarchar(100),
@p_Dept nvarchar(max),
@p_TableName nvarchar(50)
as
BEGIN
IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=@p_TableName)) 
BEGIN
--Declare @set nvarchar(50)
Declare @set nvarchar(500)
--Replace your query to 
set @set='insert into '+@TableName+'(Name,City,Dept) values(''' + @name + ''',''' + @City + ''',''' + @Dept + ''')'
Print 'Success'
END
else
BEGIN
Print 'Table is Not there'
END
END


I guess the statement should be:

set @set=''insert into ''+@TableName+''(Name,City,Dept) values('''''' + @name + '''''','''''' + @City + '''''','''''' + @Dept + '''''')''


这篇关于ASP.NET存储的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆