c# set list equal to method that generates the list

Jul 14 2021 2:36 PM

 Hey all,

 

Needing a little help with the code below. I am stuck and cannot figure it out. What is highlighted in yellow is where I am getting the error. However my ultimate goal is to reference the list I created in GetEmail(), reference that too emaillist. Any help will be greatly appreciated!

 

Thanks alot

 

 

public bool Email() //Approved Email
        {
            try
            {
                //string emaillist = GetEmail();
                bool transactionSuccessful = false;
                List emaillist = new List();
                //emaillist = string = GetEmail();
                bool emailAttachment = false; //attach file into email
                
                //List emaillist = GetEmail().ToList();
                foreach (string emailTo in emaillist)
                {
                    string emailCC = "Nelson, Sebastian  ";
                    string emailSubject = "Response";
                    string emailBody = "Your request has been processed.";

                    GlobalFunctions obj_HandleOutlook = new GlobalFunctions();
                    obj_HandleOutlook.HandleOutlook(emailTo, emailCC, emailSubject, emailBody);

                    return transactionSuccessful;
                }
            }
            catch (System.Exception ex)
            {
                return TransactionFailure;
            }
        return TransactionSuccessful; 
        }

        public string  GetEmail()
        {
            string Email = "";
            List maillist = new List();
            string name = Environment.UserName;
            
            string connectionString = "Server = HIIAPPLEW036; Database=dbPAR_DailyTasks; Trusted_Connection = True";
            //string queryString = "SELECT NetworkID, Email FROM [dbHostDataDaily].[dbo].[vw_Employee_Basic] WHERE [NetworkID] =  '" + name.ToString() + "'";
            string queryString = "SELECT [a].NetworkID, [a].Email FROM [dbHostDataDaily].[dbo].[vw_Employee_Basic] as [a]" +
                                   "INNER JOIN [dbPAR_DailyTasks].[dbo].[tbl_SUBJECTIVE_Bill_QUE] as [b]" +
                                    "ON [a].NetworkID = [b].IE_APPROVER " +
                                        "WHERE [NetworkID] =  [b].IE_APPROVER";
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();
                {
                    while (reader.Read())
                    {
                      Email = reader["Email"].ToString();
                      if (!(maillist.Contains(Email)))
                        {
                            maillist.Add(Email);
                        }
                    }
                }
                connection.Close();
                for (int i = 0; i < maillist.Count - 1; i++)
                {
                    Console.WriteLine(maillist[i].ToString());

                }
            }
            return maillist; // Getting an error right here "Cannot implicity convert type 'System.Collections.Generic.List


Answers (1)