I have got a single function using OleDb:
I think maybe the use of a list to find out if a specific table exist could be made better, like this: Check for MS Access database table if not exist create it
But I also want to understand the old code given, to learn something.
Questions:
1) What does the exact restrictionValues mean in the example code below? ( not solved)
2) Why row.ItemArray[2] of all cells is containing the table names? (solved)
3) Is there a better way to get table names out of a database? (solved)
This is the code I have got:
public List<string> GetTableNames(string tableName, string[] field_names)
{
List<string> retTableNames = new List<string>();
if (dbConnection != null)
{
dbConnection.Open();
string strSQL = "SELECT * ";
string[] restrictionValues = new string[4] { null, null, null, "TABLE" };
OleDbCommand cmd = new OleDbCommand(strSQL, dbConnection);
try
{
/*search after all possible tables in dataset*/
DataTable schemaInformation = dbConnection.GetSchema("Tables", restrictionValues);
foreach (DataRow row in schemaInformation.Rows)
{
retTableNames.Add(row.ItemArray[2].ToString());
}
}
catch
{
retTableNames = null;
}
}
return retTableNames;
}