Sunday, March 11, 2012

Value of first parameter to Stored proc always goes as a blank.

Can you post some sample code?

I can assure you, there is no ghost monkey in your code eating up your parameter value. If it's setup properly it will show up at the database end.

Here is what I'd look for

a) ParameterName being correct
b) parameter direction being correct
c) parameter data type being correct
d) parameter size being correct.
e) Your actually supplying a value to the parameter.

Sahil Malik [MVP C#]
Author: Pro ADO.NET 2.0
http://www.winsmarts.com


Sahil, Thanks for the time, I did check the Parameter details in the debug screen, the name, value and direction are present as I had set them. Here is a sample code fyi.

object obj = new object();

ADODB.Recordset objrecs = new ADODB.RecordsetClass();

oCmd.ActiveConnection = (ADODB.Connection)m_MyConn;

oCmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc;

oCmd.CommandText = "GetName";

oCmd.Parameters.Append(oCmd.CreateParameter("@.intDummy", ADODB.DataTypeEnum.adVarChar,

ADODB.ParameterDirectionEnum.adParamInput,4,"2"));

oCmd.Parameters.Append(oCmd.CreateParameter("@.strNumber", ADODB.DataTypeEnum.adVarChar,

ADODB.ParameterDirectionEnum.adParamInput,4,"2"));

oCmd.Parameters.Append(oCmd.CreateParameter("@.strName",ADODB.DataTypeEnum.adVarChar,

ADODB.ParameterDirectionEnum.adParamOutput,100,""));

oCmd.Execute(out obj, ref obj,-1);

string str = oCmd.Parameters["@.strName"].Value.ToString();

-*************--

Create procedure GetName(@.intDummy varchar(4), @.strNumber varchar(4), @.strName varchar(100) out)

as

Select Name from Customers where number = @.strNumber

Thanks.


What is the relevance of this line?

oCmd.Execute(out obj, ref obj,-1);


How can I execute the command other than this?

No comments:

Post a Comment