private void btnConnect_Click(object sender, EventArgs e) { GetConnectionString(); // Query Database for Table Names MSSQL loDB = new MSSQL(csConnectionString); string lsSQL = "SELECT TABLE_NAME FROM information_schema.tables;"; try { loDB.openConnection(); DataTable lsDT = loDB.QueryDBDataset(lsSQL); if (loDB.csErr != null && loDB.csErr != string.Empty) { MessageBox.Show("Error: " + loDB.csErr); return; } cboTables.Items.Clear(); if (lsDT != null && lsDT.Rows.Count > 0) { foreach (DataRow lsDR in lsDT.Rows) { cboTables.Items.Add(lsDR[0].ToString()); } } } catch (Exception lsEx) { MessageBox.Show("Error: " + lsEx.Message); } loDB.closeConnection(); MessageBox.Show("Connected Successfully!"); }
private void cboTables_SelectedIndexChanged(object sender, EventArgs e) { GetConnectionString(); // Query Database for Table Names Int32 liLID = 0; MSSQL loDB = new MSSQL(csConnectionString); string lsSQL = "SELECT * FROM " + cboTables.SelectedItem.ToString() + ";"; try { loDB.openConnection(); DataTable lsDT = loDB.QueryDBDataset(lsSQL); grdData.DataSource = null; if (lsDT != null) { grdData.DataSource = lsDT; } } catch { liLID = 0; } loDB.closeConnection(); }