When you assign table.LayTeamId in the line a couple of lines above where you are seeing the exception:
table.LayTeamId = tableDesc;
I expect that tableDesc
is assigning a value to table.LayTeamId
that cannot be parsed to an Int
and then blows up when you try to parse it here:
command.CommandText = String.Format("SELECT TeamDesc FROM Team WHERE TeamId ={0}", int.Parse(table.LayTeamId));
NOTE:
This is a bad way to form queries by concatenating strings. This will leave you vulnerable to SQL Injection attacks if you aren't careful. Use parameterized queries to sanitize your queries before you execute them on your database.