vc的ado中调用存储过程,带有字符串类型的输出参数

xbottle001 2009-08-02 08:31:01
语句是这样:
select a from a_table where ad_id = 0010101
这时候a是唯一的字符串。
那么我要怎么在存储过程中写,才能让这个字符串输出呢?
以及在vc的ado中要怎样写呢?
...全文
61 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xbottle001 2009-08-02
  • 打赏
  • 举报
回复
找到了

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[aaaaproc]
@IndexValue int,
@Combostring nvarchar (256) output,
@NLen INT
AS
BEGIN
declare @sql nvarchar(4000)

SET @sql ='SELECT @Combostring = row_value
FROM combobox_temp_table
WHERE index_value = '+ltrim(@IndexValue )
exec sp_executesql @sql ,N'@Combostring int output',@Combostring output
--这里写错了,@Combostring 不用该是int类型
select @sql as '@sql'
select @Combostring as '@Combostring'
END
--sql server执行如下
USE [aaaaaaaa]
GO
DECLARE @IndexValue int,
@Combostring varchar (256) ,
@NLen INT

EXEC [dbo].[aaaaproc]
@IndexValue = 1,@Combostring = @Combostring output,@NLen = 0

SELECT @Combostring as '@Combostring'
GO
xbottle001 2009-08-02
  • 打赏
  • 举报
回复
是这样的:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[aaaaproc]
@IndexValue int,
@Combostring nvarchar (256) output,
@NLen INT
AS
BEGIN
declare @sql nvarchar(4000)

SET @sql ='SELECT @Combostring = row_value
FROM combobox_temp_table
WHERE index_value = '+ltrim(@IndexValue )
exec sp_executesql @sql ,N'@Combostring int output',@Combostring output
select @sql as '@sql'
select @Combostring as '@Combostring'
END
--sql server执行如下
USE [aaaaaaaa]
GO
DECLARE @IndexValue int,
@Combostring varchar (256) ,
@NLen INT

EXEC [dbo].[aaaaproc]
@IndexValue = 1,@Combostring = @Combostring output,@NLen = 0

SELECT @Combostring as '@Combostring'
GO

但是在执行的时候,会提示我所取得的字符串:
消息 245,级别 16,状态 1,第 1 行
在将 nvarchar 值 '我所取得的字符串 ' 转换成数据类型 int 时失败。
-狙击手- 2009-08-02
  • 打赏
  • 举报
回复
create proc pr_test
@s varchar(100) output
as
begin
select @s = a from a_table where ad_id = '0010101'
end
go


ado你就gg 吧,一大把一大把的

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧