How about passing the SQL statement to the new forms constructors and
having a method handle the grid. This is just an
example.........................
private void LoadMainGrid(string SQL)
{
try
{
DataTable table = fillTable(SQL);
foreach (DataRow row in table.Rows)
{
if (row["SimFile"].ToString().Length != 0)
populateGrid(yourDataGridName,
row["aFieldYouWantDisplayed"].ToString(),
row["aFieldYouWantDisplayed"].ToString(),
row["aFieldYouWantDisplayed"].ToString());
}
}
catch (Exception e) { }
finally { cn.Close(); }
}
private void populateGrid(DataGridView dg, string row1, string
row2, string row3)
{
dg.Rows.Add((row1 + ";" + row2 + ";" + row3).Split(';'));
dg.Columns[2].Width = 250;
}
public DataTable FillTable(string SQL)
{
DataConnection();
DataTable table = new DataTable();
using (OleDbDataAdapter da = new OleDbDataAdapter(SQL,
cn))
{
da.Fill(table);
}
cn.Close();
return table;
}
public void DataConnection()
{
if (cn.State == ConnectionState.Open)
cn.Close();
cn.ConnectionString = "YourConnectionString"
cn.Open();
}
|