String[9]: the Size property has an invalid size of 0???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm attempting to insert data to a table via an ExecuteNonQuery call on a
SqlCommand sproc object, but I keep getting the error displayed in the
subject line and can't, for the life of me, figure out what the
ExecuteNonQuery call doesn't like. If I attempt to use the sproc from within
SQL Server Management Studio, the insert performs flawlessly.

The sproc is as follows:
ALTER PROC [dbo].[AddDrawing]

@DeptID int,
@DrawingCode smallint,
@Description varchar(60),
@Category char(4),
@ManHours decimal(5, 2),
@CaddRatio decimal(5, 2),
@CompRatio decimal(5, 2),
@LastUser varchar(20),
@NewDrawingID int output,
@NewTimeStamp timestamp output

AS
INSERT INTO ProjectDrawings (DeptID,
DrawingCode,
Description,
Category,
ManHours,
CaddRatio,
CompRatio,
LastUser)
VALUES (@DeptID,
@DrawingCode,
@Description,
@Category,
@ManHours,
@CaddRatio,
@CompRatio,
@LastUser)

SELECT @NewDrawingID = DrawingID,
@NewTimeStamp = LastChanged
FROM ProjectDrawings

RETURN

I am adding to the Parameters collection for the SqlCommand object as follows:
cm.Parameters.AddWithValue("@DeptID", _deptID);
cm.Parameters.AddWithValue("@DrawingCode", _drawingCode);
cm.Parameters.AddWithValue("@Description", _description);
cm.Parameters.AddWithValue("@Category", _category);
cm.Parameters.AddWithValue("@ManHours", _manHours);
cm.Parameters.AddWithValue("@CaddRatio", _caddRatio);
cm.Parameters.AddWithValue("@CompRatio", _compRatio);
cm.Parameters.AddWithValue("@LastUser", _lastUser);
cm.Parameters.AddWithValue("@NewDrawingID", _drawingID);
cm.Parameters["@NewDrawingID"].Direction = ParameterDirection.Output;
cm.Parameters.AddWithValue("@NewTimeStamp", _timeStamp);
cm.Parameters["@NewTimeStamp"].Direction = ParameterDirection.Output;

I use essentially the same routine for inserting values into various other
tables in my database, but this is the only one that is giving me a hard
time. What can I do to track down and correct whatever it is that's causing
me to get the error message? Any thanks will be greatly appreciated.

Allen
 
Hi,
Can you post the exception you are getting and where exactly the
exception occurs ?
Please specify in details.
 
Me too is getting this. And started getting this the moment I added the
parameter to the collection with direction = output. Once I commented it out,
it worked.
My declaration is - sqlComm.Parameters.Add(New SqlParameter("@UserName",
SqlDbType.VarChar)).Direction = ParameterDirection.Output. The other one with
direction=returnvalue is working fine.
I get the error for string(21)...and this declaration is the 21st in my
code. Just like yours is the 9th.
 
Back
Top