# One cell too many with datatool and longtable

I am aware of the previous post datatool with longtable, but it didn't solve my problem.

I've a document with 10 tables or so, for each table I use this piece of code:

\DTLsetseparator{;}
\begin{center}
\begin{longtable}{|c|c|c|}
\caption[De berekende bronsterkte van de buis]{De berekende bronsterkte van de buis} \label{tbl:kundt2} \\
\hline
\endfoot
\endlastfoot
\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\ifthenelse{\value{DTLrowi}>0}{
\1 & \2 & \3 \\ \hline }{}}
\end{longtable}
\end{center}


My csv file

1;2;3;
444;555;666;
111;222;333;


etc., I know that one is fine.

Since I'm Dutch I need to use the ; sign for separating my csv values. Everything is working great even for tables longer then 4 pages but every single time there is an extra empty cell at the last row. I tried to change this line:

\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\ifthenelse{\value{DTLrowi}>0}{
\1 & \2 & \3 \\ \hline }{}}


to:

\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\ifthenelse{\value{DTLrowi}>0}{
\\ \hline \1 & \2 & \3}{}}


But then I get the extra empty cell at the first row. What am I doing wrong?

datatool apparently doesn't protect its internals enough to be used in this context. You can hide the switching in \noalign as below. I also removed the center environment as it has no effect on longtable.

\documentclass{article}

\usepackage{datatool,longtable}

\begin{document}
\DTLsetseparator{;}

\begin{longtable}{|c|c|c|}
\caption[De berekende bronsterkte van de buis]{De berekende bronsterkte van de buis} \label{tbl:kundt2} \\
\hline
\endfoot
\endlastfoot
\noalign\bgroup
\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\egroup\ifthenelse{\value{DTLrowi}>0}{
\1 & \2 & \3 \\ \hline }{}\noalign\bgroup}\egroup
\end{longtable}

\end{document}