Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
there is a class which on of it's properties is object type,because it may valued by Different type(string,boolean,or,...)
C#
public class paramout
{
    public string param { set; get; }
    public object value { set; get; }
}

I have a function which returns output parameters of any Stored Procedure by this class.
C#
public paramout  ExecProced(String spName,List<InputParameterMapping> mapIn,List<OutputParameterMapping> mapOut)
      {
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = Sqlc;
          cmd.CommandText = spName;
          cmd.CommandType = System.Data.CommandType.StoredProcedure;
          SqlParameterCollection objParamColl = cmd.Parameters;
          try
          {
              if (mapIn != null)
                  foreach (ParameterMappingInput map in mapIn)
                      AddInputParameterToCollection(map.ParameterName, map.Value, objParamColl);
              if(mapOut!=null)
                  foreach(ParameterMappingOutput  map in mapOut)
                      AddOutputParameterToCollection(map.ParameterName,map.ValueType,objParamColl);
              OpenConnection(Sqlc);
              cmd.ExecuteNonQuery();// for insert/delete/update
              CloseConnection(Sqlc);
              if(mapOut!=null && objParamColl!=null)
              {
                  List<paramout> lst=new List<paramout>();
                  foreach(SqlParameter p in objParamColl)
                  {
                      lst.Add(new paramout() { param = p.ParameterName, value =p.Value});
                  }
                  return lst; //error
              }
                 return null;
          }
          catch (Exception ex)
          {
              throw ex;
          }


the error is:Cannot implicitly convert type 'paramout' to'System.Collections.Generic.List<paramout>'
Posted
Updated 5-Feb-14 8:16am
v3
Comments
OriginalGriff 5-Feb-14 13:59pm    
What's your method definition look like?
OriginalGriff 5-Feb-14 13:59pm    
Oh, and the "lst" declaration
Sergey Alexandrovich Kryukov 5-Feb-14 14:05pm    
In what line? Show lst declaration. Of course these two types are not assignable in any way...
—SA

define the method like this
C#
public List<paramout> ExecProced(String spName,List<InputParameterMapping> mapIn,List<outputparametermapping> mapOut)
 
Share this answer
 
v2
Comments
mit62 5-Feb-14 14:40pm    
Oh,yes.it was Careless
Karthik_Mahalingam 5-Feb-14 14:49pm    
it happens sometimes :)
Siva Hyderabad 6-Feb-14 0:30am    
Hai karthik,wr r u? busy na? You are not in CP
Karthik_Mahalingam 6-Feb-14 1:17am    
hi siva
tell me, today bit busy.
Karthik_Mahalingam 6-Feb-14 1:48am    
i have got lot of work this week, thats y. but even though i am spending some time in CP..
my First priority is INFOSYS after that only CP.
CP is for Fun,Learning,Helping Others,knowledge sharing etc......
Please see comments to the question. You cannot ask questions like that, not showing relevant code.

It will work if you, for example, define
C#
System.Collections.Generic.List<paramout> lst = new System.Collections.Generic.List<paramout>();


—SA
 
Share this answer
 
Comments
mit62 5-Feb-14 14:37pm    
I improved question
Sergey Alexandrovich Kryukov 5-Feb-14 15:17pm    
Okay, good, now please mark the line (with some comment) where the exception is thrown...
—SA

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