错误返回c#代码中的输出参数值 [英] error in return the output parameter value in c# code

查看:63
本文介绍了错误返回c#代码中的输出参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友



Hi friends

public string deleteapplicationfromstage11(business.Commonpropertis proper)
        {
            string storedprocedure = "sp_deleteapplicationfromstage1";
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@applicationnumber", proper.APPLICATIONNUMBER);
            SqlParameter message=new SqlParameter("message",SqlDbType.VarChar,100);
            param[1] = new SqlParameter("@messge", message);
            message.Direction = ParameterDirection.Output;
            string result = dbconn.getoutputparametervalue(storedprocedure, param);
            return result;
        }



和getoutputparametervalue方法是




and getoutputparametervalue method is

public string getoutputparametervalue(string procedurename, SqlParameter[] param)
        {
            string result = null;
            try
            {
                open();
                command = new SqlCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = procedurename;
                command.Parameters.AddRange(param);
                command.Connection = conn;
                command.ExecuteScalar();
                result =Convert.ToString(command.Parameters["message"].Value);
                return result;
            }
            catch (Exception ex)
            {
                Console.Write("Error - Connection.executestoredprocedure" + procedurename + "\nException:" + ex.StackTrace.ToString());
                return null;
            }
            finally
            {
                if (conn != null)
                {
                    close();
                }
            }


        }



和我的存储过程


and my stored procedure

ALTER procedure [dbo].[sp_deleteapplicationfromstage1](@applicationnumber int, @message varchar(100) out )
as
begin
declare @admissionnumber int
select @admissionnumber=AdmissionNumber from School.dbo.StudentAdmission_details where ApplicationNumber=@applicationnumber
if @admissionnumber is not null
begin
set @message=' this application was registered to admission,so it cannot be deleted'
--return @message
end
else
begin
delete from School.dbo.StudentApplication_details where ApplicationNumber=@applicationnumber
set @message ='This application is deleted'
--return @message
end
end







,错误是






and the error is

No mapping exists from object type System.Data.SqlClient.SqlParameter to a known managed provider native type.

推荐答案

你错过了''a'':

You missed an ''a'':
param[1] = new SqlParameter("@messge", message);




ALTER procedure [dbo].[sp_deleteapplicationfromstage1](@applicationnumber int, @message varchar(100) out )

尝试:

Try:

param[1] = new SqlParameter("@message", message);




ALTER procedure [dbo].[sp_deleteapplicationfromstage1](@applicationnumber int, @message varchar(100) out )

那可能会修复它!


你好,



这个错误基本上是由于错误的数据类型或没有转换正确的数据!!!!

因此请正确检查您的代码和数据类型
Hi there,

this error is basically throw due to wrong datatype or not converting proper data!!!!
so check your code properly and datatype


这篇关于错误返回c#代码中的输出参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆