Click here to Skip to main content
15,891,703 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys what im trying to do here is to read a data(string) coming from my MySql Database but in a form of List<string> for a faster processing and to save memory.

C#
public void GetFace(string name)
        {
            
            using (var Connection = new MySqlConnection(connectionString))
            {
                Connection.Open();
                try
                {
                    using (MySqlCommand selectcommand = Connection.CreateCommand())
                    {
                        selectcommand.CommandText = "select columnname from tablename";
                        using (MySqlDataReader reader = selectcommand.ExecuteReader())
                        {
                            var Names_list = new List<string>();
                            while (reader.Read())
                            {
                                Names_list.Add(name);
                                Attendance(Names_list.ToArray()); // it is a method which has a string[] paramater
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
            }
        }


but as I reload the database there is seem to be no changes.
Attendance method is a method that updates the database:
here is the Attendance method:

C#
private void Attendance(string[] name)
        {
            
            using (var Connection = new MySqlConnection(connectionString))
            {
                Connection.Open();
                try
                {
                    DateTime CurrentDate;
                    CurrentDate = DateTime.Now;
                    using (MySqlCommand selectcommand = Connection.CreateCommand())
                    {
                        selectcommand.CommandText = "UPDATE tablename SET " + CurrentDate.ToString("MM_dd_yyyy") + " = '" + CurrentDate + "' WHERE columnname = '" + name + "'";
                        selectcommand.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
            }
        }


thank you for your answer
Posted
Comments
[no name] 29-Jan-16 0:58am    
In your code: Names_list.Add(name);

What is the value of name. Secondly you are adding value to list and where the problem?
Member 11968073 29-Jan-16 2:31am    
oh thank you for you response.
i Got the correct answer i just need to use String Builder for me to read the List
thank you so much
Sinisa Hajnal 29-Jan-16 7:24am    
You have several problems with this code, one of the most glaring ones is lack of transaction for the loop. What happens if in the middle of the reader loop something breaks? You'll have part of the list inserted and part not.
Member 11968073 30-Jan-16 22:57pm    
thank you Sinisa Hajinal for your concern. Im such a newbie when it comes to database coding. What could i do to make this code better?

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