SqlParameter inputParam = new SqlParameter("name", value);
SqlParameter outputParam = new SqlParameter("name", value);
outputParamDirection = ParameterDirectionOutput;
sqlCmdaddParameter(input);
sqlCmdaddParameter(output);
sqlCmdexecuteNonQuery("storedProcName");
object outputValue = outputParamValue;
更详细的请看msdn的技术资源库里的类库参考,上面都有。
建立包
create or replace package test is TYPE filename_array IS TABLE OF varchar ( ); filename filename_array; end test;
建立存储过程
lishixinzhi/Article/program/Oracle/201311/18265
或者用ParameterDirectionReturnValue;来接收返回值
MyCommandParameters["@return"]Direction = ParameterDirectionReturnValue;
MyCommandExecuteNonQuery();
ResponseWrite(MyCommandParameters["@return"]ValueToString());
还有一种做法是直接返回两个集合,一个是Select count(1),一个是Select xxx
Select count(1) From ;Select From
方法一 分割
例:通过SQL Server存储过程传送数组参数删除多条记录
eg ID 值为'1,2,3' 以下存储过程就是删除表中id号为1,2,3的记录:
CREATE PROCEDURE DeleteNews
@ID nvarchar(500)
as
DECLARE @PointerPrev int
DECLARE @PointerCurr int
DECLARE @TId int
Set @PointerPrev=1
while (@PointerPrev < LEN(@ID))
Begin
Set @PointerCurr=CharIndex(',',@ID,@PointerPrev)
if(@PointerCurr>0)
Begin
set @TId=cast(SUBSTRING(@ID,@PointerPrev,@PointerCurr-@PointerPrev) as int)
Delete from News where ID=@TID
SET @PointerPrev = @PointerCurr+1
End
else
Break
End
--删除最后一个,因为最后一个后面没有逗号,所以在循环中跳出,需另外再删除
set @TId=cast(SUBSTRING(@ID,@PointerPrev,LEN(@ID)-@PointerPrev+1) as int)
Delete from News where ID=@TID
GO
这个方法麻烦不?于是又有另外一种方法——临时表
方法二 Table对象
传3个参数,都是数组形式还有时间类型用存储过程更新
@Oid = 1,2,3,4
@Did = 111,222,333,444
@DateArr = '2007-1-1,2007-1-2,2007-1-3,2007-1-4'
CREATE proc Test999
@Oid nvarchar(1000) --ID1
,@Did nvarchar(1000) --ID2
,@DateArr nvarchar(1000) --日期
AS
DECLARE @id1s varchar(8000), @id2s varchar(8000), @dates varchar(8000)
set @id1s=@Oid
set @id2s=@Did
set @dates = @DateArr
-- 调用函数实现处理
SELECT @id1s=@id1s, @id2s=@id2s,@dates = @dates
UPDATE A SET terminate_time = Bdt
FROM [Table] A,(
SELECT
id1 = CONVERT(int, Desk_idvalue),
id2 = CONVERT(int, room_idvalue),
dt = CONVERT(datetime, terminate_timevalue)
FROM dbof_splitstr(@id1s) Desk_id, dbof_splitstr(@id2s) room_id, dbof_splitstr(@dates) terminate_time
WHERE Desk_idid = room_idid
AND Desk_idid = terminate_timeid
) B
WHERE ADesk_id = BID1 AND Aroom_id = BID2
GO这个还用到一个函数f_splitstr
CREATE FUNCTION dbof_splitstr(
@str varchar(8000)
)RETURNS @r TABLE(id int IDENTITY(1, 1), value varchar(5000))
AS
BEGIN
DECLARE @pos int
SET @pos = CHARINDEX(',', @str)
WHILE @pos > 0
BEGIN
INSERT @r(value) VALUES(LEFT(@str, @pos - 1))
SELECT
@str = STUFF(@str, 1, @pos, ''),
@pos = CHARINDEX(',', @str)
END
IF @str > ''
INSERT @r(value) VALUES(@str)
RETURN
END
declare @str varchar(500)
declare @insert varchar(8000)
select @insert = 'insert into youTable values '
select @str='str1,1,1,1,1|str2,2,2,2,2|str3,3,3,3,5|str4,4,4,45,4'
select @str=@insert+'('''+@str+''')'
select @str = REPLACE(@str,',',''',''')
select @str = REPLACE(@str,'|',''') '+CHAR(13)+@insert+'(''')
print @str
--exec(@str) 动态执行下生成的语句就好了
--print 结果如下:
insert into youTable values ('str1','1','1','1','1')
insert into youTable values ('str2','2','2','2','2')
insert into youTable values ('str3','3','3','3','5')
insert into youTable values ('str4','4','4','45','4')
#include <stdioh>
int main()
{
struct test {
int a;
char s[10] ;
double d ;
} tr[3] , tw[3] ={
{1,"hello1" , 100 },
{2,"hello2" , 90},
{3,"hello3", 200}
} ; //定义一个结构体数组
FILE fp ;
fp=fopen("structdat" , "wb" );
if ( fp == NULL )
return -1 ;
fwrite( (char)tw , sizeof(struct test), 3 , fp ); //将数组写入文件
fclose(fp);
//以上完成写 *** 作
fp=fopen("structdat" , "rb" );
if ( fp == NULL )
return -1 ;
fread( (char)tr , sizeof(struct test), 3 , fp ); //从文件中读三个结构体的数据,也可以一个一个的读
fclose(fp);
//输出读到的数据
{
int i;
for(i=0;i<3;i++ )
printf("%d %s %lf\n" , tr[i]a , tr[i]s, tr[i]d );
}
return 0;
}
以上就是关于C#三层中使用SqlParameter数组设置和获得存储过程参数全部的内容,包括:C#三层中使用SqlParameter数组设置和获得存储过程参数、Oracle存储过程返回数组的方法、如何接收存储过程查询出的结果或传出的数组等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)