I’m coding a tool to count all entries in a table. My question is, how can I get all the tables of an existing database? I’m using Microsoft SQL Server 2008 R2 and I already have a method to get a string array of a table:
List<string> lResult = new List<string>();
SqlConnection sqlConn10 = new SqlConnection(sConnStr);
sqlConn10.Open();
SqlCommand sqlComm10 = new SqlCommand("SELECT " + sColumn + " FROM " + sTable + " WHERE " + sWhere, sqlConn10);
SqlDataReader myReader10 = sqlComm10.ExecuteReader();
int i = 0;
try
{
while (myReader10.Read())
{
lResult.Add(myReader10.GetString(0));
i++;
}
}
catch
{
myReader10.Close();
sqlConn10.Close();
}
return lResult.ToArray();
}
Either you use the sql-command
or you use a DataTable