How do you Insert serial port received data into MSSQL server database in C# winfroms .NET framework?

Hi everybody. I’m beginner in c# winforms and I want to insert some serial port received data into MSSQL server database. I have written 2 separate codes which one of them receive data from serial port and the other one insert some data into database and both of them work correctly but when I want to merge these codes I got into trouble. can anybody help me?

and Here is my code :

    private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {            
        int bytesToRead = serialPort1.BytesToRead;
        int intBuffer;
        intBuffer = serialPort1.BytesToRead;
        byte[] byteBuffer = new byte[intBuffer];
        serialPort1.Read(byteBuffer, 0, intBuffer);
        this.Invoke(new EventHandler(DoUpDate));
        using (SqlConnection dbConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Default.DESKTOP-H4O1L0D\source\repos\salam\salam\meteodata.mdf;Integrated Security=True"))
        {
            dbConnection.Open();
            using (SqlCommand insertCmd = new SqlCommand(@"INSERT INTO mtable VALUES(@id,@datetime,@data,@humid,@tmp,@pressure,@windd,@winds,@precip)", dbConnection))
            {                  
                Random random = new Random();
                String str = serialPort1.ReadLine();
                str = Regex.Replace(str, "[^0-9/.]", "");         
                insertCmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(random.Next(0, 100000));
                insertCmd.Parameters.Add("@DateTime", SqlDbType.DateTime).Value = DateTime.Now;
                insertCmd.Parameters.Add("@data", SqlDbType.VarChar).Value = str;                    
                string[] arr = str.Split('/');                    
                switch (arr[0])
                {
                    case "111":
                        tmp = float.Parse(arr[2]);
                        hmd = float.Parse(arr[1]);
                        break;
                    case "112":
                        press = float.Parse(arr[1]);                            
                        break;
                    case "113":
                        wds = float.Parse(arr[4]);
                        wdd = float.Parse(arr[3]);                           
                        break;
                    case "115":
                        prcp = float.Parse(arr[2]);                            
                        break;
                }                   
                insertCmd.Parameters.AddWithValue("tmp", tmp);
                insertCmd.Parameters.AddWithValue("humid", hmd);
                insertCmd.Parameters.AddWithValue("pressure", press);
                insertCmd.Parameters.AddWithValue("winds", wds);
                insertCmd.Parameters.AddWithValue("windd", wdd);
                insertCmd.Parameters.AddWithValue("precip", prcp);                    
                insertCmd.ExecuteNonQuery();
            }
        }            
    }        
    private void DoUpDate(object s, EventArgs e)
    {
        try
        {
            sendRead.Text = serialPort1.ReadLine();
            sendRead.Text = Regex.Replace(sendRead.Text, "[^0-9/.]", "");                
        }

        catch (System.Exception ex)
        {
            sendRead.Text = ex.Message;
        }
    }