Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » ADO.NET » Downloads
 
Add your own
alternative version

An Experimental Performance Comparison on the Methods to Pass Structured Data to SQL Server Stored Procedures from ADO.NET

, 23 Dec 2009 CPOL
This article makes an experimental comparison on the performance of the different methods to pass structured data to SQL Server Stored Procedure parameters from ADO.NET.
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UploadByTextType]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[UploadByTextType];
GO

CREATE PROCEDURE [dbo].[UploadByTextType]
	@DataInTextType AS TEXT
AS
BEGIN
	DECLARE @T AS TABLE([ID] INT, [Name] VARCHAR(250), [Score] INT)
	DECLARE @RowSeparator AS INT; DECLARE @ItemSeparator AS INT;
	DECLARE @P AS INT
	DECLARE @DataLength AS INT
	DECLARE @Item AS INT
	DECLARE @C AS VARCHAR(1)
	DECLARE @ID AS VARCHAR(20)
	DECLARE @Name AS VARCHAR(250)
	DECLARE @Score AS VARCHAR(20)
	
	SET @RowSeparator = 0; SET @ItemSeparator = 1
	
	SET @P = 1; SET @Item = 1; SET @ID = ''; SET @Name = ''; SET @Score = ''
	SET @DataLength = DATALENGTH(ISNULL(@DataInTextType, ''));
	
	WHILE @P  <= @DataLength
	BEGIN
		SET @C = SUBSTRING(@DataInTextType, @P, 1)
		
		IF ASCII(@C) = @RowSeparator BEGIN
			INSERT INTO @T VALUES(CAST(@ID AS INT), @Name, CAST(@Score AS INT));
			SET @Item = 1; SET @ID = ''; SET @Name = ''; SET @Score = '';
		END ELSE
		BEGIN
			IF @Item = 1 
				BEGIN IF ASCII(@C) = @ItemSeparator BEGIN SET @Item = @Item + 1 END ELSE BEGIN SET @ID = @ID + @C END END
			ELSE IF @Item = 2
				BEGIN IF ASCII(@C) = @ItemSeparator BEGIN SET @Item = @Item + 1 END ELSE BEGIN SET @Name = @Name + @C END END
			ELSE IF @Item = 3
				BEGIN IF ASCII(@C) = @ItemSeparator BEGIN SET @Item = @Item + 1 END ELSE BEGIN SET @Score = @Score + @C END END
		END
		
		SET @P = @P + 1
	END;
	
	SELECT * FROM @T
END;

GO


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dr. Song Li

United States United States
I have been working in the IT industry for some time. It is still exciting and I am still learning. I am a happy and honest person, and I want to be your friend.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150331.1 | Last Updated 23 Dec 2009
Article Copyright 2009 by Dr. Song Li
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid