Quantcast
Channel: SQL Server Data Access forum
Viewing all articles
Browse latest Browse all 4164

SQL int to string

$
0
0

Hi everyone,
I have a problem trying to retrieve the value of a string variable from VB.NET code behind. After converting the value from integer to nvarchar, I see the result ok in SQL. But when trying to retrieve it in VB, it always defaults to "1"

have anyone here encountered any similar issue?    (see code below)

                                                                                           

BEGIN
SET NOCOUNT ON;
BEGIN TRY
BEGIN TRANSACTION

DECLARE @NoConnected int, @MaxNoCon int = 2, @Con int, @ConIsAvailable bit
DECLARE @NumberRecords int, @RowCount int
SET @NoConnected = 0
CREATE TABLE #Check_Connections
(
 RowID int IDENTITY(1, 1), 
 DBName nvarchar(30),
 NumberOfConnections int,
 LoginName nvarchar(30)
)

INSERT INTO #Check_Connections (DBName, NumberOfConnections,  LoginName)
SELECT 
DB_NAME(dbid) AS DBName,
COUNT(dbid) AS NumberOfConnections, 
loginame AS LoginName 
FROM     
sys.sysprocesses
where DB_NAME(dbid) = 'anydatabasename'
GROUP BY dbid, loginame

SET @NumberRecords = @@ROWCOUNT 
SET @RowCount = 1  PRINT '@RowCount = ' + cast(@RowCount as nvarchar(10)) 
-- loop through all records in the temporary table using the WHILE loop construct
WHILE @RowCount <= @NumberRecords 

BEGIN
SET @Con = (SELECT NumberOfConnections FROM #Check_Connections WHERE RowID = @RowCount) 
SET @NoConnected = @NoConnected + @Con PRINT '@NoConnected = ' + cast(@NoConnected as nvarchar(10)) 

SET @Con = 0
SET @RowCount = @RowCount + 1
END

DROP TABLE #Check_Connections  

if @NoConnected  < @MaxNoCon 
SET @ConIsAvailable = 1 -- TRUE there are still available connections
else
SET @ConIsAvailable = 0 -- FALSE no connections available

SELECT @ConIsAvailable [ConIsAvailable],  @NoConnected [NoConnected] 

COMMIT TRANSACTION
END TRY

BEGIN CATCH --in case of errors
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION --dont execute anything
SELECT 'There was an error! ' + ERROR_MESSAGE()

END CATCH
END


Viewing all articles
Browse latest Browse all 4164


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>