Skip to content

Instantly share code, notes, and snippets.

@amarodeabreu
Created February 23, 2021 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amarodeabreu/646abba49e3b67b0534823027b67eb6a to your computer and use it in GitHub Desktop.
Save amarodeabreu/646abba49e3b67b0534823027b67eb6a to your computer and use it in GitHub Desktop.
/// <summary>
/// Get database tables to populate grid
/// </summary>
private void GetTables()
{
// Get all SQL tables for the db defined in the settings file
var sql = "SELECT TABLE_NAME As Tables FROM " + Properties.Settings.Default.Database + ".INFORMATION_SCHEMA.TABLES with (nolock) WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME ASC";
try
{
var dtDatatable = QueryDatabase(ConnectionString, sql).Tables[0];
gridView1.Columns.Clear();
tablesGrid.DataSource = null;
tablesGrid.DataSource = dtDatatable;
gridView1.BestFitColumns();
tablesGrid.RefreshDataSource();
gridView3.Columns.Clear();
gridControl1.DataSource = null;
gridControl1.DataSource = dtDatatable;
gridView3.BestFitColumns();
gridControl1.RefreshDataSource();
}
catch (Exception ex)
{
// Show alert on error - no message boxes, using popups
var alertInfo = new AlertInfo("Error", ex.Message);
var control = new AlertControl { FormLocation = AlertFormLocation.BottomRight };
control.Show(ParentForm, alertInfo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment