First thing to note is that when you do :
var a = from b in DB.GetTable<Table>() select b;
foreach (var x in a)
{
It's going to load every row (instead of effecting a db query) which could be costly if there is a lot of row.
Here is a Linq query which i think will do what you want (it will work if the name in txtName.Text
contains only text):
using (DBDataContext DB = new DBDataContext(strConnectionString))
{
string name = txtName.Text.ToString(),
int nbDuplicate = (from b in DB.GetTable<Table>()
where b.Name==name || b.Name.StartsWith(name+" ")
&& (b.Name.Length>=name.Length+2 &&
b.Name[name.Length+1]>='0'
&& b.Name[name.Length+1]<='9'
)
select b).Count();
name += " " + nbDuplicate;
.....
}