protected void executeQuery(object sender, EventArgs e) { //try //{ Database db; DataTable dt; Label title = new Label(); if (connectionSelector.SelectedItem.Text == "local") { try { db = new Database(); dt = db.executeQueryLocal(queryString.Text); } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } } else { ConnInfo info = new ConnInfo(); try { db = new Database(); string query = "SELECT * FROM Connection WHERE ID=" + connectionSelector.SelectedItem.Value; dt = db.executeQueryLocal(query); if (dt.HasErrors) { throw new ODBC2KMLException("Unknown Database error"); } } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } try { info = ConnInfo.getConnInfo(int.Parse(connectionSelector.SelectedItem.Value)); } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } db.setConnInfo(info); try { dt = db.executeQueryRemote(queryString.Text); } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } } resultsPanel.Visible = true; resultsPanel.Controls.Add(new LiteralControl("<span class=\"connectionStyle\"> Database Query Results</span>")); resultsPanel.Controls.Add(new LiteralControl("<div class=\"mainBoxP\">")); resultsPanel.Controls.Add(new LiteralControl("<table cellpadding=\"5\" cellspacing=\"0\" class=\"mainBox2\">")); resultsPanel.Controls.Add(new LiteralControl("<tr><td>")); resultsPanel.Controls.Add(new LiteralControl("<div class=\"omainBox4\">")); resultsPanel.Controls.Add(new LiteralControl("<table class=\"omainBox5\" cellspacing=\"0\" cellpadding=\"0\">")); resultsPanel.Controls.Add(new LiteralControl("<tr>")); foreach (DataColumn dc in dt.Columns) { resultsPanel.Controls.Add(new LiteralControl("<td><b>" + dc.ColumnName + "<br/></b></td>")); } resultsPanel.Controls.Add(new LiteralControl("</tr><tr><td><br/></td></tr>")); foreach (DataRow dr in dt.Rows) { resultsPanel.Controls.Add(new LiteralControl("<tr>")); foreach (Object data in dr.ItemArray) { resultsPanel.Controls.Add(new LiteralControl("<td>" + data.ToString() + "</td>")); } resultsPanel.Controls.Add(new LiteralControl("</tr>")); } resultsPanel.Controls.Add(new LiteralControl("</table>")); resultsPanel.Controls.Add(new LiteralControl("<div align=\"right\" style=\"padding-top: 20px;\">")); resultsPanel.Controls.Add(new LiteralControl("<input type=\"submit\" ID=\"hideResults\" value=\"Hide Results\" class=\"button\" />")); resultsPanel.Controls.Add(new LiteralControl("</div>")); resultsPanel.Controls.Add(new LiteralControl("</td></tr>")); resultsPanel.Controls.Add(new LiteralControl("</div>")); resultsPanel.Controls.Add(new LiteralControl("</span>")); ModalPopupExtender6.Show(); //} /*catch(Exception exception) { errorPanel1.Visible = true; errorPanel1.Controls.Add(new LiteralControl("<div style=\"color: black\"><p>"+exception.Message+"</p></div>")); errorPanel1.Controls.Add(new LiteralControl("<script type=\"text/javascript\">$(\"#errorPanel1\").dialog('open')</script>")); }*/ }
protected void Page_Load(object sender, EventArgs e) { Database db = new Database(); DataTable dt; Label title = new Label(); string connID = Request["con"]; string table = Request["tbl"]; string tblQuery = "SELECT * FROM " + table; ConnInfo info = new ConnInfo(); try { db = new Database(); string query = "SELECT * FROM Connection WHERE ID=" + connID; dt = db.executeQueryLocal(query); if (dt.HasErrors) { throw new ODBC2KMLException("There was a problem getting the connection information from the local database"); } } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.conErrorText, errorPanel1); eh.displayError(); return; } //Cycle through each row and column foreach (DataRow row in dt.Rows) { foreach (DataColumn col in dt.Columns) { //Set all connInfo switch (col.ColumnName) { case "name": info.setConnectionName(row[col].ToString()); break; case "dbName": info.setDatabaseName(row[col].ToString()); break; case "userName": info.setUserName(row[col].ToString()); break; case "password": info.setPassword(row[col].ToString()); break; case "port": info.setPortNumber(row[col].ToString()); break; case "address": info.setServerAddress(row[col].ToString()); break; case "type": info.setDatabaseType(int.Parse(row[col].ToString())); break; case "protocol": info.setOracleProtocol(row[col].ToString()); break; case "serviceName": info.setOracleServiceName(row[col].ToString()); break; case "SID": info.setOracleSID(row[col].ToString()); break; default: break; } } }//End outer loop db.setConnInfo(info); try { dt = db.executeQueryRemote(tblQuery); } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.tblErrorText, errorPanel1); eh.displayError(); return; } //resultsPanel.Visible = true; bool altTables = true; Page.Controls.Add(new LiteralControl("<span style=\"color: white; font-weight:bold; background-color:rgb(26,49,76);\"> " + table + " Database Query Results</span>")); Page.Controls.Add(new LiteralControl("<div>")); Page.Controls.Add(new LiteralControl("<table cellpadding=\"5\" cellspacing=\"2\">")); Page.Controls.Add(new LiteralControl("<tr><td>")); Page.Controls.Add(new LiteralControl("<div>")); Page.Controls.Add(new LiteralControl("<table cellspacing=\"2\" cellpadding=\"2\" rules=\"all\">")); Page.Controls.Add(new LiteralControl("<tr class=\"titleConn\">")); foreach (DataColumn dc in dt.Columns) { Page.Controls.Add(new LiteralControl("<td><b>" + dc.ColumnName + "<br/></b></td>")); } Page.Controls.Add(new LiteralControl("</tr>")); foreach (DataRow dr in dt.Rows) { if (altTables) { Page.Controls.Add(new LiteralControl("<tr class=\"evenConn\">")); foreach (Object data in dr.ItemArray) { Page.Controls.Add(new LiteralControl("<td>" + data.ToString() + "</td>")); } Page.Controls.Add(new LiteralControl("</tr>")); } else { Page.Controls.Add(new LiteralControl("<tr class=\"oddConn\">")); foreach (Object data in dr.ItemArray) { Page.Controls.Add(new LiteralControl("<td>" + data.ToString() + "</td>")); } Page.Controls.Add(new LiteralControl("</tr>")); } altTables = !altTables; } Page.Controls.Add(new LiteralControl("</table>")); Page.Controls.Add(new LiteralControl("</td></tr>")); Page.Controls.Add(new LiteralControl("</div>")); Page.Controls.Add(new LiteralControl("</span>")); }
protected void executeQuery(object sender, EventArgs e) { //try //{ Database db; DataTable dt; Label title = new Label(); if (connectionSelector.SelectedItem.Text == "local") { try { db = new Database(); dt = db.executeQueryLocal(queryString.Text); } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } } else { ConnInfo info = new ConnInfo(); try { db = new Database(); string query = "SELECT * FROM Connection WHERE ID=" + connectionSelector.SelectedItem.Value; dt = db.executeQueryLocal(query); if (dt.HasErrors) { throw new ODBC2KMLException("Unknown Database error"); } } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } try { info = ConnInfo.getConnInfo(int.Parse(connectionSelector.SelectedItem.Value)); } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } db.setConnInfo(info); try { dt = db.executeQueryRemote(queryString.Text); } catch (ODBC2KMLException ex) { ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1); eh.displayError(); return; } } resultsPanel.Visible = true; resultsPanel.Controls.Add(new LiteralControl("<span class=\"connectionStyle\"> Database Query Results</span>")); resultsPanel.Controls.Add(new LiteralControl("<div class=\"mainBoxP\">")); resultsPanel.Controls.Add(new LiteralControl("<table cellpadding=\"5\" cellspacing=\"0\" class=\"mainBox2\">")); resultsPanel.Controls.Add(new LiteralControl("<tr><td>")); resultsPanel.Controls.Add(new LiteralControl("<div class=\"omainBox4\">")); resultsPanel.Controls.Add(new LiteralControl("<table class=\"omainBox5\" cellspacing=\"0\" cellpadding=\"0\">")); resultsPanel.Controls.Add(new LiteralControl("<tr>")); foreach (DataColumn dc in dt.Columns) { resultsPanel.Controls.Add(new LiteralControl("<td><b>" + dc.ColumnName + "<br/></b></td>")); } resultsPanel.Controls.Add(new LiteralControl("</tr><tr><td><br/></td></tr>")); foreach (DataRow dr in dt.Rows) { resultsPanel.Controls.Add(new LiteralControl("<tr>")); foreach (Object data in dr.ItemArray) { resultsPanel.Controls.Add(new LiteralControl("<td>" + data.ToString() + "</td>")); } resultsPanel.Controls.Add(new LiteralControl("</tr>")); } resultsPanel.Controls.Add(new LiteralControl("</table>")); resultsPanel.Controls.Add(new LiteralControl("<div align=\"right\" style=\"padding-top: 20px;\">")); resultsPanel.Controls.Add(new LiteralControl("<input type=\"submit\" ID=\"hideResults\" value=\"Hide Results\" class=\"button\" />")); resultsPanel.Controls.Add(new LiteralControl("</div>")); resultsPanel.Controls.Add(new LiteralControl("</td></tr>")); resultsPanel.Controls.Add(new LiteralControl("</div>")); resultsPanel.Controls.Add(new LiteralControl("</span>")); ModalPopupExtender6.Show(); //} /*catch(Exception exception) * { * errorPanel1.Visible = true; * errorPanel1.Controls.Add(new LiteralControl("<div style=\"color: black\"><p>"+exception.Message+"</p></div>")); * errorPanel1.Controls.Add(new LiteralControl("<script type=\"text/javascript\">$(\"#errorPanel1\").dialog('open')</script>")); * }*/ }