[RESOLVED] cannot convert from 'System.Collections.Generic.IList-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] cannot convert from 'System.Collections.Generic.IList

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    793

    Resolved [RESOLVED] cannot convert from 'System.Collections.Generic.IList

    i have a strange thing here, i have a WCF service that has an operation contract defined like this

    Code:
    public bool SynchMenuItemsToCDB(IList<EcashMenuSynchModel> model)
            {
                con = new SqlConnection(strCon);
    
                cmdinsert = new SqlCommand("sp_Addmenuitems"); //needs to be created
    
                cmdinsert.CommandType = CommandType.StoredProcedure;
    
                cmdinsert.Connection = con;
    
                bool Error = false;
                
                try
                { 
                    con.Open();
    
                    foreach (EcashMenuSynchModel ecash in model)
                    {
                        Error = false;
                        cmdinsert.Parameters.Add("@MENUITEMID", SqlDbType.Int).Value = ecash.MENUITEMID;
                        cmdinsert.Parameters.Add("@PDC_ID", SqlDbType.Int).Value = ecash.PDC_ID;
                        cmdinsert.Parameters.Add("@PRD_ID", SqlDbType.Int).Value = ecash.PRD_ID;
                        cmdinsert.Parameters.Add("@PDC_DESCRIPTION", SqlDbType.Int).Value = ecash.PDC_DESCRIPTION;
                        cmdinsert.Parameters.Add("@PRD_SELLINGPRICE", SqlDbType.Int).Value = ecash.PRD_SELLINGPRICE;
                        cmdinsert.Parameters.Add("@BREAKID", SqlDbType.Int).Value = ecash.BreakID;
                        cmdinsert.Parameters.Add("@CUTOFFDATE", SqlDbType.Int).Value = ecash.CUTOFFDATE;
                        cmdinsert.Parameters.Add("@SCHOOLID", SqlDbType.Int).Value = ecash.SCHOOLID;
                        cmdinsert.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Error = true;
                    Logger.LoggerClient logger = new Logger.LoggerClient();
                    //Collect Data
                    Logger.LoggerModel modelS = new Logger.LoggerModel();
                    modelS.iTYPEID = Convert.ToInt32(GenericEnum.Logging_Type.ECASH_SYCH);
                    modelS.sLOGGER_CLASS = "eCashDatalayer";
                    modelS.sLOGGER_DESCRIPTION = ex.Message;
                    modelS.sLOGGER_FUNCTION = "SynchMenuItemsToCDB";
                    modelS.sLOGGER_LOGGEDINUSERID = "";
                    modelS.sLOGGER_PAGE = "NA";
                    modelS.sLOGGER_VALUE = "NA";
                    logger.LogIncident(modelS);
                }
                finally
                {
                    con.Close();
                }
    
                return Error;
            }
    as you can see this function accept "IList<EcashMenuSynchModel>" which is the Ilist of my model class

    i have a WPF application that consumes this service. so i first prepare that list like this

    Code:
     public IList<EcashMenuSynchModel> LoadMenuItems()
            {
                FirebirdSql.Data.FirebirdClient.FbConnection con = new FbConnection(strCon);
    
                FbCommand cmdselectFDB = new FbCommand();
    
                StringBuilder sb = new StringBuilder();
    
                sb.Append("SELECT M.MENUITEMID, M.PDC_ID, m.PRD_ID, M.PRD_SELLINGPRICE, P.PRD_DESCRIPTION, M.BREAKID, M.CUTOFFDATE, M.SCHOOLID ");
                sb.Append("From MENUITEMSECASH M ");
                sb.Append("INNER JOIN PRODUCT P ");
                sb.Append("ON m.PRD_ID = p.PRD_ID");
    
                cmdselectFDB.CommandText = sb.ToString();
    
                cmdselectFDB.Connection = con;
    
                FbDataAdapter da = new FbDataAdapter();
    
                da.SelectCommand = cmdselectFDB;
    
                DataTable dt = new DataTable();
    
                List<EcashMenuSynchModel> m_Break = null;
                try
                {
                    con.Open();
    
                    da.Fill(dt);
    
                    if (dt.Rows.Count > 0)
                    {
    
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            EcashMenuSynchModel m = new EcashMenuSynchModel();
                            m.MENUITEMID = Convert.ToInt32(dt.Rows[i][0]);
                            m.PDC_ID = Convert.ToInt32(dt.Rows[i][1]);
                            m.PRD_ID = Convert.ToInt32(dt.Rows[i][2]);
                            m.PRD_SELLINGPRICE = Convert.ToDecimal(dt.Rows[i][3]);
                            m.PDC_DESCRIPTION= Convert.ToString(dt.Rows[i][4]);
                            m.BreakID = Convert.ToInt32(dt.Rows[i][5]);
                            m.CUTOFFDATE = Convert.ToDateTime(dt.Rows[i][6]);
                            m.SCHOOLID = Convert.ToInt32(dt.Rows[i][7]);
                            m_Break.Add(m);
                        }
                    }
    
                }
                catch (Exception ex)
                {
                    //log to a file
                }
                finally
                {
                    con.Close();
                }
                return m_Break;
            }
    and i use it like this


    Code:
              IList<EcashMenuSynchModel> m_Transactions = null;
    
               
                m_Transactions = ecash.LoadMenuItems();
    
                bool Resultsfailer = DataLayerDirect.SynchMenuItemsToCDB(m_Transactions);
    now i get a VS exception before i even compile this

    Code:
    Error	32	The best overloaded method match for 'Ecash_Money_Synch_Demo.DataLayer.IeCashDatalayerClient.SynchMenuItemsToCDB(System.Collections.Generic.List<Ecash_Money_Synch_Demo.DataLayer.EcashMenuSynchModel>)' has some invalid arguments	G:\AvantEdgeDevelopment\Ecash_NewLocation\Sync App\Ecash_Money_Synch_Demo\Ecash_Money_Synch_Demo\SynchMeals.xaml.cs	115	34	Ecash_Money_Synch_Demo
    and this

    Code:
    Error	33	Argument 1: cannot convert from 'System.Collections.Generic.IList<Ecash_Money_Synch_Demo.DataLayer.EcashMenuSynchModel>' to 'System.Collections.Generic.List<Ecash_Money_Synch_Demo.DataLayer.EcashMenuSynchModel>'	G:\AvantEdgeDevelopment\Ecash_NewLocation\Sync App\Ecash_Money_Synch_Demo\Ecash_Money_Synch_Demo\SynchMeals.xaml.cs	115	70	Ecash_Money_Synch_Demo

    I Followed the solution of this thread to overcome my problem, but still it does not help


    http://forums.silverlight.net/forums/p/215142/509566.aspx
    Last edited by vuyiswamb; Jul 5th, 2011 at 03:23 PM.

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,572

    Re: cannot convert from 'System.Collections.Generic.IList

    Your SynchMenuItemsToCDB methode requires a List not an IList
    Does the thread on Silverlight.net (http://forums.silverlight.net/forums/t/233513.aspx) didn't provide you the answer?
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    793

    Re: cannot convert from 'System.Collections.Generic.IList

    i did thanks , i posted them all at the same time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.