Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends

C#
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;
        }

and getoutputparametervalue method is

C#
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
SQL
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.
Posted

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

SQL
ALTER procedure [dbo].[sp_deleteapplicationfromstage1](@applicationnumber int, @message varchar(100) out )
Try:
C#
param[1] = new SqlParameter("@message", message);

SQL
ALTER procedure [dbo].[sp_deleteapplicationfromstage1](@applicationnumber int, @message varchar(100) out )
That will probably fix it!
 
Share this answer
 
Comments
baskaran chellasamy 23-Feb-13 3:53am    
No,still same error occured
OriginalGriff 23-Feb-13 4:11am    
Ok, which line?
And what does the data on that line look like?
baskaran chellasamy 23-Feb-13 4:18am    
in executescaler(),the error occured.if apply data in storedprocedure alone its working fine. but the same value throw error in this executescaler() method.
OriginalGriff 23-Feb-13 4:34am    
In which case, check the type of proper.APPLICATIONNUMBER - I can't see what it is, but the chances are it's not a simple type that SqlParameter recognises.
[no name] 23-Feb-13 4:33am    
use command.ExecuteNonQuery(); behalf of executescaler() and try
Hi there,

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900