只要你的机器上有.net framework 1.1 和 IIS,然后你做个ASPX页面并拷贝到任意虚拟目录下就可以了:
Return results: [ " + dt.Rows.Count + " ]"; this.Panel_Result.Controls.Add(hc); DataGrid dg = new DataGrid(); dg.ID = "DG_" + this.Panel_Result.Controls.Count.ToString(); dg.Width = new Unit("100%"); dg.AutoGenerateColumns = true; dg.DataSource = dt; if(dt.Columns.Count > 0) dg.DataBind(); this.Panel_Result.Controls.Add(dg); } else { System.Web.UI.HtmlControls.HtmlGenericControl hc = new HtmlGenericControl("div"); hc.Attributes.Add("style","width:100%;color:red;background-color:lightgrey;"); hc.InnerHtml = sql + "
Execute SQL : [ " + AccessDBManager.ExecuteNonQuerySQL(sql) + " ]"; this.Panel_Result.Controls.Add(hc); } if(AccessDBManager.errorMessage != "") { this.Label_Message.Text += "
" + AccessDBManager.errorMessage; } } public class AccessDBManager { public AccessDBManager() { // // TODO: Add constructor logic here // } public static string errorMessage; public static string DBConnectionString; private OleDbConnection oleConnection = null; private OleDbCommand oleCommand = null; private OleDbDataAdapter sqlCommand = null; private static void LogError(Exception error) { errorMessage = error.Message; } //connect to oracle and excute more than a sql #region need open database connection for more than a sql public bool OpenDatabase() { bool success = false; try { this.oleConnection = new OleDbConnection(DBConnectionString); this.oleConnection.Open(); success = true; } catch(Exception error) { LogError(error); } return success; } public bool CloseDatabase() { bool success = false; try { this.oleCommand.Dispose(); this.sqlCommand.Dispose(); this.oleConnection.Close(); this.oleConnection.Dispose(); this.oleCommand = null; this.sqlCommand = null; this.oleConnection = null; success = true; } catch(Exception error) { LogError(error); } return success; } public int MultiExecuteNonQuerySQL(string sqlStr) { int count = -99; try { this.oleCommand = new OleDbCommand(sqlStr, this.oleConnection); count = this.oleCommand.ExecuteNonQuery(); } catch(Exception error) { LogError(error); } return count; } public DataTable MultiGetTableBySQL(string sqlStr) { DataTable dataTable = new DataTable(); try { this.sqlCommand = new OleDbDataAdapter(sqlStr,this.oleConnection); sqlCommand.Fill(dataTable); } catch(Exception error) { LogError(error); } return dataTable; } #endregion //finish only a sql in oracle #region don't need open database connection public static int ExecuteNonQuerySQL(string sqlStr) { int count = -99; try { using (OleDbConnection connection = new OleDbConnection(DBConnectionString)) { connection.Open(); using (OleDbCommand ocm=new OleDbCommand(sqlStr,connection) ) { count = ocm.ExecuteNonQuery(); } connection.Close(); } } catch(Exception error) { LogError(error); } return count; } public static DataTable GetTableBySQL(string sqlStr) { DataTable dataTable = new DataTable(); try { using (OleDbDataAdapter myCommand = new OleDbDataAdapter (sqlStr,DBConnectionString) ) { myCommand.Fill(dataTable); } } catch(Exception error) { LogError(error); } return dataTable; } #endregion } <body> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0" o> <TR id="history"> <TD style="WIDTH:150px" valign="top"><input style="border:solid 1px black;" type="button" value="View History" onclick="var tempC = document.getElementById('Label_History');if(tempC.style.display != 'none') {tempC.style.display = 'none';this.value='view history!'} else {tempC.style.display = '';this.value='hide history!'}"><input style="border:solid 1px black;" type="button" value="Clear History" onclick="document.getElementById('Label_History').innerHTML = '';document.getElementById('isClearHistory').value='clear';document.getElementById('Label_History').style.display='none';"><input type="hidden" value="" name="history" id="isClearHistory"></TD> <TD><div id="Label_History" runat="server" style="color:blue;display:none;"></div> </TD> </TR> <TR> <TD> connection string: </TD> <TD> <asp:TextBox CssClass="TextBox" id="TextBox_ConnStr" runat="server"></asp:TextBox></TD> </TR> <TR> <TD valign="top"> sql string : </TD> <TD> <asp:TextBox CssClass="TextArea" id="TextBox_SqlStr" runat="server" TextMode="MultiLine"></asp:TextBox></TD> </TR> <TR> <TD></TD> <TD> <asp:Button id="Button_Execute" runat="server" Text="Execute"></asp:Button></TD> </TR> <TR> <TD colspan="2"> <asp:Label id="Label_Message" runat="server" ForeColor="Red"></asp:Label></TD> </TR> <TR> <TD colSpan="2"> <asp:Panel id="Panel_Result" runat="server"></asp:Panel></TD> </TR> </TABLE> </form> </body> </html>
<%@ Page LANGUAGE="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Web " %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Web.UI.HtmlControls" %> <%@ Import Namespace="System "%> <%@ Import Namespace="System.Collections "%> <%@ Import Namespace="System.ComponentModel "%> <%@ Import Namespace="System.Drawing "%> <%@ Import Namespace="System.Web.UI "%> <%@ Import Namespace="System.Web.SessionState "%> <html> <HEAD> <title>exesql</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <style> .TextBox { WIDTH: 90% } .TextArea { WIDTH: 90%; HEIGHT: 200px } </style> </HEAD> <script language="C#" runat="server"> private void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) this.TextBox_ConnStr.Text = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = "+ Server.MapPath("db.mdb"); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button_Execute.Click += new System.EventHandler(this.Button_Execute_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button_Execute_Click(object sender, System.EventArgs e) { if(Request.Form["history"].Trim() == "clear") this.Label_History.InnerHtml = ""; this.Label_History.InnerHtml += "<xmp style=/"width:95%;background-color:lightgrey;float:left;border:solid 1px black;margin:1px 1px 1px 1px;/">" + this.TextBox_SqlStr.Text + ""; this.Label_Message.Text = ""; this.Panel_Result.Controls.Clear(); AccessDBManager.DBConnectionString = this.TextBox_ConnStr.Text.Trim(); if(this.TextBox_SqlStr.Text.IndexOf("|~|") > 0) { string sqlStrList = this.TextBox_SqlStr.Text.Replace("^","{@@}"); foreach(string s in sqlStrList.Split(new char[]{'^'})) { if(s.Length > 5) { exe(s.Replace("{@@}","^")); } } } else { exe(this.TextBox_SqlStr.Text); } } private void exe(string sql) { AccessDBManager.errorMessage = ""; if(sql.ToLower().StartsWith("select")) { DataTable dt = AccessDBManager.GetTableBySQL(sql); System.Web.UI.HtmlControls.HtmlGenericControl hc = new HtmlGenericControl("div"); hc.Attributes.Add("style","width:100%;color:red;background-color:lightgrey;"); hc.InnerHtml = sql + "
Return results: [ " + dt.Rows.Count + " ]"; this.Panel_Result.Controls.Add(hc); DataGrid dg = new DataGrid(); dg.ID = "DG_" + this.Panel_Result.Controls.Count.ToString(); dg.Width = new Unit("100%"); dg.AutoGenerateColumns = true; dg.DataSource = dt; if(dt.Columns.Count > 0) dg.DataBind(); this.Panel_Result.Controls.Add(dg); } else { System.Web.UI.HtmlControls.HtmlGenericControl hc = new HtmlGenericControl("div"); hc.Attributes.Add("style","width:100%;color:red;background-color:lightgrey;"); hc.InnerHtml = sql + "
Execute SQL : [ " + AccessDBManager.ExecuteNonQuerySQL(sql) + " ]"; this.Panel_Result.Controls.Add(hc); } if(AccessDBManager.errorMessage != "") { this.Label_Message.Text += "
" + AccessDBManager.errorMessage; } } public class AccessDBManager { public AccessDBManager() { // // TODO: Add constructor logic here // } public static string errorMessage; public static string DBConnectionString; private OleDbConnection oleConnection = null; private OleDbCommand oleCommand = null; private OleDbDataAdapter sqlCommand = null; private static void LogError(Exception error) { errorMessage = error.Message; } //connect to oracle and excute more than a sql #region need open database connection for more than a sql public bool OpenDatabase() { bool success = false; try { this.oleConnection = new OleDbConnection(DBConnectionString); this.oleConnection.Open(); success = true; } catch(Exception error) { LogError(error); } return success; } public bool CloseDatabase() { bool success = false; try { this.oleCommand.Dispose(); this.sqlCommand.Dispose(); this.oleConnection.Close(); this.oleConnection.Dispose(); this.oleCommand = null; this.sqlCommand = null; this.oleConnection = null; success = true; } catch(Exception error) { LogError(error); } return success; } public int MultiExecuteNonQuerySQL(string sqlStr) { int count = -99; try { this.oleCommand = new OleDbCommand(sqlStr, this.oleConnection); count = this.oleCommand.ExecuteNonQuery(); } catch(Exception error) { LogError(error); } return count; } public DataTable MultiGetTableBySQL(string sqlStr) { DataTable dataTable = new DataTable(); try { this.sqlCommand = new OleDbDataAdapter(sqlStr,this.oleConnection); sqlCommand.Fill(dataTable); } catch(Exception error) { LogError(error); } return dataTable; } #endregion //finish only a sql in oracle #region don't need open database connection public static int ExecuteNonQuerySQL(string sqlStr) { int count = -99; try { using (OleDbConnection connection = new OleDbConnection(DBConnectionString)) { connection.Open(); using (OleDbCommand ocm=new OleDbCommand(sqlStr,connection) ) { count = ocm.ExecuteNonQuery(); } connection.Close(); } } catch(Exception error) { LogError(error); } return count; } public static DataTable GetTableBySQL(string sqlStr) { DataTable dataTable = new DataTable(); try { using (OleDbDataAdapter myCommand = new OleDbDataAdapter (sqlStr,DBConnectionString) ) { myCommand.Fill(dataTable); } } catch(Exception error) { LogError(error); } return dataTable; } #endregion } <body> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0" o> <TR id="history"> <TD style="WIDTH:150px" valign="top"><input style="border:solid 1px black;" type="button" value="View History" onclick="var tempC = document.getElementById('Label_History');if(tempC.style.display != 'none') {tempC.style.display = 'none';this.value='view history!'} else {tempC.style.display = '';this.value='hide history!'}"><input style="border:solid 1px black;" type="button" value="Clear History" onclick="document.getElementById('Label_History').innerHTML = '';document.getElementById('isClearHistory').value='clear';document.getElementById('Label_History').style.display='none';"><input type="hidden" value="" name="history" id="isClearHistory"></TD> <TD><div id="Label_History" runat="server" style="color:blue;display:none;"></div> </TD> </TR> <TR> <TD> connection string: </TD> <TD> <asp:TextBox CssClass="TextBox" id="TextBox_ConnStr" runat="server"></asp:TextBox></TD> </TR> <TR> <TD valign="top"> sql string : </TD> <TD> <asp:TextBox CssClass="TextArea" id="TextBox_SqlStr" runat="server" TextMode="MultiLine"></asp:TextBox></TD> </TR> <TR> <TD></TD> <TD> <asp:Button id="Button_Execute" runat="server" Text="Execute"></asp:Button></TD> </TR> <TR> <TD colspan="2"> <asp:Label id="Label_Message" runat="server" ForeColor="Red"></asp:Label></TD> </TR> <TR> <TD colSpan="2"> <asp:Panel id="Panel_Result" runat="server"></asp:Panel></TD> </TR> </TABLE> </form> </body> </html>