string filenumber=Select ID from table.
This is never going to work.
Here are two beginners articles in CodeProject for connection to a SQL database with C#
Beginners guide to accessing SQL Server through C#[
^]
How to connect SQL Database to your C# program, beginner's tutorial[
^]
ID being a number should be stored in an
int
or a
long
not a
string
so that line should be something like
long filenumber = GetIDFromTable();
where you will write the function
GetIDFromTable
by studying the articles I gave you above.
Once you have the file number creating a filename based on it is trivial (see
String.Format Method (System) | Microsoft Docs[
^])
string filename = string.Format("T{0}", filenumber);
Your code
Directory.CreateDirectory(path+filename);
also won't work. CreateDirectory does what it says ... it creates a directory (folder) not a file. So don't pass a file name into it.
You also need to read the documentation on creating a file or folder -
How to: Create a File or Folder (C# Programming Guide) | Microsoft Docs[
^]Use Path.Combine to get the fully pathed filename e.g.
string fullFileName = System.IO.Path.Combine(path, fileName);
That should keep you going for a while. You might need to come back with a new question about the code
if(table1)
name=table1;
else if(table2)
name=table2;
but at the moment it's not clear what you are trying to do