I am reading from a table with a million records, I perform some modifications to some columns and I would like to save them back in bulk. I would like to perform a bulk update after every 10000 records.
I'm using .Net Core 3.1
My code :
public void FixText()
        {
            SqlConnection cnn = new SqlConnection(strConn);
            string queryString = "SELECT ClientID, ServerName, Text FROM  [dbo].[Client]";
            SqlCommand selectCmd = new SqlCommand(queryString, cnn);
            cnn.Open();
            int j = 0;
            SqlDataReader reader = selectCmd.ExecuteReader();
            List<Client> clients = new List<Client>();
            try
            {
                while (reader.Read())
                {
                    j++;
                    ClientID = (int)reader["ClientID"];
                    ServerName = reader["ServerName"].ToString();
                    Text = reader["Text"].ToString();
                    
                    
                    //Modify Text & set ServerName
                    string Text = UpdateText(Text);
                    if text.StartWith("doo"){ServerName = "re";}
                    //perform bulk update
                    if (j > 10000)
                    {
                        Client client = new Client()
                        {
                            ClientID = (int)ClientID,
                            ServerName = ServerName,
                            Text = Text,
                        };
                        clients.Add(client);
                        //I'm struggling here on what to use to do a bulk update
                       
                        j = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                reader.Close();
            }
            cnn.Close();
        }
Any Help is appreciated!
 
     
    