troubleshooting Question

Convert Generic list to data

Avatar of r3nder
r3nderFlag for United States of America asked on
.NET ProgrammingC#ASP.NET
13 Comments1 Solution491 ViewsLast Modified:
I am getting an error when I try to use a data class to retrieve data that I store in a list

it says Cannot implicitly convert type 'System.Collections.Generic.List<MessageBoard.Data.MessageData>' to 'MessageBoard.Data.MessageData

Data.Message m = new Data.Message();
                Data.MessageData md = m.GetEditThread(ID);
                //List<Data.MessageData> md = new List<Data.MessageData>();
                //List<Data.MessageData> md = m.GetEditThread(ID);
                lblPostID.Text =;
                radtxtBody = md.Body;
                radtxtSubject = md.Subject;
I have my sql statement and my reader to add each item to the stubs in Message and my stubs in message data

This is message data
    public class MessageData
         public MessageData()
        public int id { get; set; }
        public string Subject { get; set; }
        public string Body { get; set;}
        public int File_Id {get; set;}
        public bool ForPublic {get;set;}
        public bool ForPrivate {get;set;}
        public bool ForKKOnly {get;set;}
        public int UserID {get;set;}
        public int PriorityID {get;set;}
This is Message
    class Message
        public List<MessageData> GetEditThread(int ID)
            List<MessageData> list = new List<MessageData>();

            string sql;
            sql = "Select id,Subject, Body,File_Id,ForPublic,ForKKOnly, ForPrivate,UserID,PriorityID FROM MsgPost Where id = '" + ID + "'";

            using (SqlConnection conn = new SqlConnection(DBConnectionString.Get(Database.Task)))
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.CommandType = System.Data.CommandType.Text;


                SqlDataReaderHelper reader = new SqlDataReaderHelper(cmd.ExecuteReader());
                if (reader.IsValid)
                    while (reader.Read())
                        list.Add(new MessageData()
                            ID = reader.GetInt("ID", 0),
                            Subject = reader.GetString("Subject", ""),
                            Body = reader.GetString("Body", ""),
                            File_Id = reader.GetInt("File_Id", 0),
                            ForPublic = reader.GetBool("ForPublic", false),
                            ForPrivate = reader.GetBool("ForPrivate", false),
                            ForKKOnly = reader.GetBool("ForKKOnly", false),
                            UserID = reader.GetInt("UserID", 0),
                            PriorityID = reader.GetInt("PriorityID", 0),
            return list;

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros