1
Answer

the Size property has an invalid size of 0

Neil Kirk

Neil Kirk

15y
11k
1
Hey there all

I am trying to retrieve data from a SQL 2008 database and receiving the above error from the following code:

                SqlParameter pID = new SqlParameter("@pID", SqlDbType.Int);
                SqlParameter pName = new SqlParameter("@pName", SqlDbType.VarChar);

                SqlCommand cmdGetInfo = new SqlCommand("sp_GetDirectoryInfo",dbConnection);
                cmdGetInfo.CommandType = CommandType.StoredProcedure;

                cmdGetInfo.Parameters.Add(pID);
                cmdGetInfo.Parameters.Add(pName);

                pName.Direction = ParameterDirection.Output;

                pID.Value = intID;
                dirToReturn.ID = intID;

                try
                {
                    cmdGetInfo.ExecuteNonQuery();
                    dirToReturn.Name = (string)cmdGetInfo.Parameters["@pName"].Value;

                    return dirToReturn;
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.ToStrin());
                }

The stored procedure is:

USE [TestDB]
GO
/****** Object:  StoredProcedure [dbo].[sp_GetDirectoryInfo]    Script Date: 03/02/2009 13:58:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sp_GetDirectoryInfo]
(
@pID int,@pName varchar OUTPUT
)
AS
SET NOCOUNT ON
SELECT @pName = Directory
FROM tblDirectoryInfo
WHERE DirectoryID = @pID
RETURN

Does anyone know why this won't work? I have done the same thing and returned integers with no problem...

I am fairly new to C#, so please bear with any stupid questions...

Thanks in advance!
Answers (1)