calling stored procedure in qt
Solved
General and Desktop
-
hi
I wrote below program to connect a stored procedure in qt:if(db.open())
{
QString testStr;testStr.reserve( 100 ); QSqlQuery query; query.setForwardOnly(true); query.prepare("{CALL getTestString(:testStr)}"); query.bindValue("testStr", testStr, QSql::Out); if( query.exec() ) { testStr = query.boundValue("testStr").toString(); if( testStr.isEmpty() ) qDebug() << "String is empty"; //always return empty string else qDebug() << testStr; } else { qDebug() << query.lastError().text(); } } else { qDebug() << "Can't connect"; }
and this is the stored procedure :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE getTestString
@key nvarchar(50) OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SET @key = 'TEST'
END
GOwhen I execute the program, it always returns:
String is empty
what's the problem? -
if(db.open()) { QString testStr ="*****"; testStr.reserve( 100 ); QSqlQuery query; query.setForwardOnly(true); query.prepare("{CALL getTestString(:testStr)}"); query.bindValue(":testStr", testStr, QSql::Out); if( query.exec() ) { testStr = query.boundValue(":testStr").toString(); if( testStr.isEmpty() ) qDebug() << "String is empty"; else qDebug() << testStr; } else { qDebug() << query.lastError().text(); } } else { qDebug() << "Can't connect"; }
-
Thank you :)