通过页面来管理数据库,进行常见的增删查改。
页面:
1<div style="background:#A4B6D7;padding:4px;">您的当前位置:系统管理»»执行SQL</div>
2<div style="vertical-align:top; margin-top:10px; margin-left:10px;">
3 <asp:TextBox ID="txtSQL" runat="server" TextMode="MultiLine" Height="80px" Width="90%" BorderStyle="Inset" OnTextChanged="txtSQL_TextChanged"></asp:TextBox>
4 <br />
5 <asp:Button ID="btnExeSql" runat="server" CssClass="button" Text="执行SQL" onClick="btnExeSql_Click" />
6 <asp:Label ID="lblExeNum" runat="server"></asp:Label>
7<a href="javascript:void(0)" onclick="Open(document.getElementById(''table'').innerHTML)">查看表结构</a>
8 <div id="table" style="display:none;">
9 <asp:GridView ID="grdTable" runat="server" Font-Size="12px" Width="100%">
10 <RowStyle HorizontalAlign="Center" CssClass="tItem" />
11 <PagerStyle CssClass="tPage" />
12 <HeaderStyle CssClass="tHeader" />
13 <AlternatingRowStyle CssClass="tAlter" />
14 <SelectedRowStyle BackColor="#F1F5FB" />
15 </asp:GridView>
16 </div>
17 <hr style="border-collapse:collapse; width:90%; text-align:left;" />
18</div>
19 <asp:GridView ID="grdSQL" runat="server" Width="100%" Visible="False">
20 <RowStyle HorizontalAlign="Center" CssClass="tItem" />
21 <PagerStyle CssClass="tPage" />
22 <HeaderStyle CssClass="tHeader" />
23 <AlternatingRowStyle CssClass="tAlter" />
24 <SelectedRowStyle BackColor="#F1F5FB" />
25 </asp:GridView>
26<script type="text/javascript">
27var Osel=document.aspnetForm;
28Osel.onsubmit=function()
29{
30 if(Osel.<%=txtSQL.ClientID %>.value=="")
31 {
32 alert("输入不可为空");
33 Osel.<%=txtSQL.ClientID %>.focus();
34 return false;
35 }
36 else if(Osel.<%=txtSQL.ClientID %>.value.indexOf("update")!=-1 || Osel.<%=txtSQL.ClientID %>.value.indexOf("delete")!=-1 || Osel.<%=txtSQL.ClientID %>.value.indexOf("truncate")!=-1)
37 {
38 if(confirm("即将执行的操作带有一定的风险,是否继续?"))
39 return true;
40 else
41 return false;
42 }
43}
44
45function Open(value)
46{
47 var TestWin=open('''','''',''toolbar=no, scrollbars=yes, menubar=no, location=no, resizable=no'');
48 TestWin.document.title="数据库表结构";
49 TestWin.document.write(value);
50}
51</script>
52
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack)
4 {
5 GetTableName();
|