Error: DataTable not returning colums.
Hello:
I am not getting anything back from the DataTable. Can someone tell me what I am missing or if I have something out of order.
public void GetFieldList(string DBTableName)
{
ClassDB DBConn = new ClassDB();
//
Connection();
createAdapter();
DBCommand.CommandText = "SELECT * FROM [" + DBTableName.ToString() + "]";
MessageBox.Show("DBCommand.CommandText= " + DBCommand.CommandText.ToString()); // Select is good.
DBDataReader = DBCommand.ExecuteReader();
//
DataTable DBTable = new DataTable();
//
string DBSQLList = "";
//
MessageBox.Show("DBTablename= " + DBTableName); // DBTableName is good.
//
foreach (DataColumn DBColumn in DBTable.Columns) // DOES NOT LOOP THRU COLUMNS <<< ERROR
{
if (DBSQLList.Length > 0)
{
DBSQLList += ", ";
}
DBSQLList += DBColumn.ColumnName;
}
//
MessageBox.Show("DBSQLList= " + DBSQLList); // Its empty.
}