First:
This might be a bad case of SQL injection! Use prepared statements (or at least proper escaping)!
Second:
Your immediate problem is the enclosing '
for the IN clause correctly:
StrSqlLines = "Select * " +
"From dbo.SqlDtaToCreate "
" WHERE DtaLineAccountToDebit = '" + Straccref + "' " +
" and DtaLineCode IN(" + joined + ")"; //notice missing ' characters
Anything enclosed by '
characters is trated as a single string. SQL server tried to parse this single string as a number, but as it was not parseable as that, it reported the error.
Third:
When using numeric data, never ever ever, never, ever (did I mention never yet?) use textual data to compare it with - that can literally kill performance. (at this scale, of course this is not significant, but keeping this in mind can save a lot of unnecessary performance analysis and debugging...)
So while this query actually works:
select * from SqlDtaToCreate where DtaLineAccountToDebit='123.567U' and DtaLineCode IN('116745','116746','116747')
It does implicit conversion of the data supplied, so the proper way is to:
select * from SqlDtaToCreate where DtaLineAccountToDebit='123.567U' and DtaLineCode IN(116745,116746,116747)