function DBwriteKL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn,NodoKlinoLink)

nNodo = num2str(NodeNum);
l = ListaDate;
   
for ii=1:l
    idData = idElabData(ii,1);
    if  idData == 0 % Se la data non è su DB (=0), scrivo i dati
        tablename = 'ELABDATADISP';
        checkT = isnan(cell2mat(DATAinsert(ii,9)));
        if checkT == 1 % il vettore Temperatura è NaN
            if strcmp(NodoKlinoLink(1,4),'ADC') || strcmp(NodoKlinoLink{1,4} ,'null') ...
                    || isempty(NodoKlinoLink{1,4}) == 1 || strcmp(NodoKlinoLink{1,4} ,'g')
                colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime',...
                    'XShift','YShift','ZShift','calcerr'};
                data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),...
                    DATAinsert(ii,4),DATAinsert(ii,5),DATAinsert(ii,6),...
                    DATAinsert(ii,7),DATAinsert(ii,8),DATAinsert(ii,10)];
            elseif strcmp(NodoKlinoLink{1,4} ,'Gradi')
                colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime',...
                    'XShift','YShift','calcerr'};
                data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),...
                    DATAinsert(ii,4),DATAinsert(ii,5),DATAinsert(ii,6),...
                    DATAinsert(ii,7),DATAinsert(ii,10)];
            end
        else
            if strcmp(NodoKlinoLink(1,4),'ADC') || strcmp(NodoKlinoLink{1,4} ,'null') ...
                    || isempty(NodoKlinoLink{1,4}) == 1 || strcmp(NodoKlinoLink{1,4} ,'g')
                colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime',...
                    'XShift','YShift','ZShift','T_node','calcerr'};
                data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),...
                    DATAinsert(ii,4),DATAinsert(ii,5),DATAinsert(ii,6),...
                    DATAinsert(ii,7),DATAinsert(ii,8),DATAinsert(ii,9),DATAinsert(ii,10)];
            elseif strcmp(NodoKlinoLink{1,4} ,'Gradi')
                colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime',...
                    'XShift','YShift','T_node','calcerr'};
                data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),...
                    DATAinsert(ii,4),DATAinsert(ii,5),DATAinsert(ii,6),...
                    DATAinsert(ii,7),DATAinsert(ii,9),DATAinsert(ii,10)];
            end
        end
        fastinsert(conn,tablename,colnames,data);
    else % altrimenti li aggiorno
        tablename = 'ELABDATADISP';
        checkT = isnan(cell2mat(DATAinsert(ii,9)));
        if checkT == 1 % il vettore Temperatura è NaN
            if strcmp(NodoKlinoLink(1,4),'ADC') || strcmp(NodoKlinoLink{1,4} ,'null') ...
                    || isempty(NodoKlinoLink{1,4}) == 1 || strcmp(NodoKlinoLink{1,4} ,'g')
                colnames = {'XShift','YShift','ZShift','calcerr'};
                data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8),...
                    DATAinsert(ii,10)];
            elseif strcmp(NodoKlinoLink{1,4} ,'Gradi')
                colnames = {'XShift','YShift','calcerr'};
                data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,10)];
            end
        else
            if strcmp(NodoKlinoLink(1,4),'ADC') || strcmp(NodoKlinoLink{1,4} ,'null') || ...
                    isempty(NodoKlinoLink{1,4}) == 1 || strcmp(NodoKlinoLink{1,4} ,'g')
                colnames = {'XShift','YShift','ZShift','T_node','calcerr'};
                data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8),...
                    DATAinsert(ii,9),DATAinsert(ii,10)];
            elseif strcmp(NodoKlinoLink{1,4} ,'Gradi')
                colnames = {'XShift','YShift','T_node','calcerr'};
                data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,9),DATAinsert(ii,10)];
            end
        end
        whereclause = ['WHERE UnitName = ''' IDcentralina ''' and ToolNameID = '''...
            DTcatena ''' and NodeNum = ''' nNodo ''' and EventDate = ''' cell2mat(DATAinsert(ii,4))...
            ''' and EventTime = ''' cell2mat(DATAinsert(ii,5)) ''' '];
        update(conn,tablename,colnames,data,whereclause)
    end
end

end
