Stored Procedure OUTPUT Parameter not working.
-
My method adds parameters to stored procedure as: public void AddParameter(string StrName, SqlDbType objType, ParameterDirection objDirection) { SqlParameter l_Param = new SqlParameter(); l_Param.ParameterName = StrName; l_Param.SqlDbType = objType; l_Param.Direction = objDirection; Command.Parameters.Add(l_Param); } public void AddParameter(string strName, SqlDbType objType, ParameterDirection objDirection, object objValue) { AddParameter(strName, objType, objDirection); } I have send parameters to stored procedure using above method and used ExecuteScaler and ExecuteReader both. But it displays error while executing stored procedure.
-
My method adds parameters to stored procedure as: public void AddParameter(string StrName, SqlDbType objType, ParameterDirection objDirection) { SqlParameter l_Param = new SqlParameter(); l_Param.ParameterName = StrName; l_Param.SqlDbType = objType; l_Param.Direction = objDirection; Command.Parameters.Add(l_Param); } public void AddParameter(string strName, SqlDbType objType, ParameterDirection objDirection, object objValue) { AddParameter(strName, objType, objDirection); } I have send parameters to stored procedure using above method and used ExecuteScaler and ExecuteReader both. But it displays error while executing stored procedure.
-
My method adds parameters to stored procedure as: public void AddParameter(string StrName, SqlDbType objType, ParameterDirection objDirection) { SqlParameter l_Param = new SqlParameter(); l_Param.ParameterName = StrName; l_Param.SqlDbType = objType; l_Param.Direction = objDirection; Command.Parameters.Add(l_Param); } public void AddParameter(string strName, SqlDbType objType, ParameterDirection objDirection, object objValue) { AddParameter(strName, objType, objDirection); } I have send parameters to stored procedure using above method and used ExecuteScaler and ExecuteReader both. But it displays error while executing stored procedure.
what is error message ?
-
My method adds parameters to stored procedure as: public void AddParameter(string StrName, SqlDbType objType, ParameterDirection objDirection) { SqlParameter l_Param = new SqlParameter(); l_Param.ParameterName = StrName; l_Param.SqlDbType = objType; l_Param.Direction = objDirection; Command.Parameters.Add(l_Param); } public void AddParameter(string strName, SqlDbType objType, ParameterDirection objDirection, object objValue) { AddParameter(strName, objType, objDirection); } I have send parameters to stored procedure using above method and used ExecuteScaler and ExecuteReader both. But it displays error while executing stored procedure.
sharad Pyakurel wrote:
SqlParameter l_Param = new SqlParameter(); l_Param.ParameterName = StrName; l_Param.SqlDbType = objType; l_Param.Direction = objDirection; Command.Parameters.Add(l_Param);
Looks like you forgot to add:l_Param.Value Add: l_Param.Value = objValue; You shouldn't be needing the other AddParameter method. All can be done in one.
-
My method adds parameters to stored procedure as: public void AddParameter(string StrName, SqlDbType objType, ParameterDirection objDirection) { SqlParameter l_Param = new SqlParameter(); l_Param.ParameterName = StrName; l_Param.SqlDbType = objType; l_Param.Direction = objDirection; Command.Parameters.Add(l_Param); } public void AddParameter(string strName, SqlDbType objType, ParameterDirection objDirection, object objValue) { AddParameter(strName, objType, objDirection); } I have send parameters to stored procedure using above method and used ExecuteScaler and ExecuteReader both. But it displays error while executing stored procedure.
For Parameter type Input it works perfectly. But with OUTPUT Parameter Type It Displays following Error in place of ExecuteScaler Method: String[1]: the Size property has an invalid size of 0. (Actually I have a Stored Procedure which takes @Amount as input and converts the input in word, here @word in output Parameter. It should convert input amount in word. Stored Procedure is right. but something wrong with executing from application. What should i do.
-
For Parameter type Input it works perfectly. But with OUTPUT Parameter Type It Displays following Error in place of ExecuteScaler Method: String[1]: the Size property has an invalid size of 0. (Actually I have a Stored Procedure which takes @Amount as input and converts the input in word, here @word in output Parameter. It should convert input amount in word. Stored Procedure is right. but something wrong with executing from application. What should i do.
As per your error message , you should mention the size of outout value (irrespective of in or string whatever your output type). please give a try and let me know. As an example: if you are exptecting to get "cheers" as a word that appears from @output valiable, then mention "6" as the size of the output parameter along with itoutput parameters type.
Thanks, Arindam D Tewary
-
As per your error message , you should mention the size of outout value (irrespective of in or string whatever your output type). please give a try and let me know. As an example: if you are exptecting to get "cheers" as a word that appears from @output valiable, then mention "6" as the size of the output parameter along with itoutput parameters type.
Thanks, Arindam D Tewary
Stored Procedure is executed after specifying the size of output parameter. I unable to get output parameters value as: string s=ExecuteScaler(cmd); Parameters value is not retrived in s. But if i cal using com_parameters[strParameter].value it gives value. I mean it gives single row data. How can i get OutPut parameters and other datas in tebular form, Like data returned by Select querry.