/* * Init all table names into a listbox */ private void InitTableNames() { // show DB tables SQLManager manager = new SQLManager(sSelectedDB); string sQuery = "Select name, id from sysobjects where xtype='U'"; // handle errors //if (manager.GetQueryDataSet(sQuery) == null) //{ // HandleQueryError(); // return; //} DataSet objSet = manager.GetQueryDataSet(sQuery); ListBoxTables.DataSource = objSet; ListBoxTables.DataTextField = "name"; ListBoxTables.DataValueField = "id"; ListBoxTables.DataBind(); manager.CloseConnection(); }
/* * Run selected query and populate the data grid */ private void ExecuteRelationalQuery(string sQuery) { SQLManager manager = new SQLManager(sSelectedDB); DataTable objTable = new DataTable(); // handle errors //if (manager.GetQueryResult(sQuery) == null) //{ // HandleQueryError(); // return; //} objTable.Load(manager.GetQueryResult(sQuery)); GridViewData.DataSource = objTable; GridViewData.DataBind(); manager.CloseConnection(); // store the data table and prepare the mining link Session.Add("queryData", objTable); Session.Add("queryTable", ListBoxTables.SelectedItem.ToString()); Session.Add("queryDB", DropDownListDatabases.SelectedItem.ToString()); }
/* * Init databases from the server */ private void InitDatabases() { SQLManager manager = new SQLManager(); string sQuery = "SELECT name, dbid FROM master..sysdatabases order by name"; // handle errors //if (manager.GetQueryDataSet(sQuery) == null) //{ // HandleQueryError(); // return; //} DataSet objSet = manager.GetQueryDataSet(sQuery); DropDownListDatabases.DataSource = objSet; DropDownListDatabases.DataTextField = "name"; DropDownListDatabases.DataValueField = "dbid"; DropDownListDatabases.DataBind(); manager.CloseConnection(); }
/* * Select all the column names for the selected table */ protected void ListBoxTables_SelectedIndexChanged(object sender, EventArgs e) { // Sets the array count variable makes sure index is not -1. if (ListBoxTables.SelectedIndex >= 0) { // clear current query GridViewData.DataSource = null; GridViewData.DataBind(); // list selected table: to be removed //Label1.Text = ListBoxTables.SelectedItem.ToString(); string sQueryText = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + ListBoxTables.SelectedItem.ToString() + "'ORDER BY ORDINAL_POSITION"; // execute query SQLManager manager = new SQLManager(sSelectedDB); DataTable objTable = new DataTable(); // handle errors //if (manager.GetQueryResult(sQueryText) == null) //{ // HandleQueryError(); // return; //} objTable.Load(manager.GetQueryResult(sQueryText)); GridViewMain.DataSource = objTable; GridViewMain.DataBind(); manager.CloseConnection(); } }