Class:
public DataTable ReadRecord(string DBCommand)
{
Connection();
SetupDataAdapter();
DBDataAdapter = new SqlDataAdapter(DBCommand, DBConnect);
try
DataTable DBDataTable = new DataTable();
DBDataAdapter.Fill(DBDataTable);
foreach (DataRow DBDataRow in DBDataTable.Rows) // GOOD - IT WORKS
TheID = DBDataRow["Name"].ToString();
MessageBox.Show("TheID=" + TheID);
}
Terminate();
return (DBDataTable);
catch
return null;
finally
Main:
private void buttonDBSelectRecord_Click(object sender, EventArgs e)
DBCommand =
" SELECT"
+ " [Name]"
+ " ,[Address_1]"
+ " FROM"
+ " [Company]"
+ " WHERE"
+ " [Company_ID] = " + "'000000'"
;
ClassDB DBConnection = new ClassDB();
ClassDB.Connection();
DBConnection.ReadRecord(DBCommand);
foreach (DataRow DBDataRow in DBDataTable.Rows) // BAD
MessageBox.Show("Login...TheID=" + TheID);