熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp.net管理mysql數據庫的小工具.

2022-06-13   來源: .NET編程 
    在 中可以通過MySQLDatadll來操作mysql數據庫寫法跟操作SQL數據庫類似下面是相關的例子
    一打開mysql數據庫
    MySqlConnection DBConn = new MySqlConnection();
    string connString =Host=;UserName=root;PassWord=root;Database=test;Port=;CharSet=utf;Allow Zero Datetime=true;
    DBConnConnectionString = connString;
    DBConnOpen();
    二執行sql命令
    string sqlstr=select * from test;
    MySqlCommand command = new MySqlCommand(sqlstr DBConn);
    commandExecuteNonQuery();
    從上面可以看出用法跟操作SQL數據庫的SqlConnectionSqlCommand非常相似下面我這裡有一個完整的例子來實現對mysql數據庫進行管理包括浏覽表結構和數據查詢修改插入刪除數據導出數據和表結構等供大家參考和互相學習代碼寫得不規范還請大家指正
    <%@ Page Language=C# %>
    <%@ Import Namespace=SystemData %>
    <%@ Import Namespace=SystemIO %>
    <%@ Import Namespace=SystemText %>
    <%@ Import Namespace=MySqlDataMySqlClient %>
    <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>
    <html xmlns=>
    <head runat=server>
    <title> MYSQL Manager (DoNet)</title>
    <style type=text/CSS>
    bodytd{font: px ArialTahoma;lineheight: px;}
    input{font:px ArialTahoma;background:#fff;border: px solid #;padding:px;height:px;}
    area{font:px Courier New Monospace;background:#fff;border: px solid #;padding:px;}
    bt {bordercolor:#bbb;background:#ddd;color:#ffffff;font:px ArialTahoma;height:px;}
    a {color: #f;textdecoration:underline;}
    a:hover{color: #f;textdecoration:none;}
    alt td{bordertop:px solid #fff;borderbottom:px solid #ddd;background:#fff;padding:px px px px;}
    alt td{bordertop:px solid #fff;borderbottom:px solid #ddd;background:#fff;padding:px px px px;}
    focus td{bordertop:px solid #fff;borderbottom:px solid #ddd;background:#ffffaa;padding:px px px px;}
    head td{bordertop:px solid #fff;borderbottom:px solid #ddd;background:#eee;padding:px px px px;fontweight:bold;}
    head td span{fontweight:normal;}
    form{margin:;padding:;}
    h{margin:;padding:;height:px;lineheight:px;fontsize:px;color:#BF;}
    li{margin:;color:#;lineheight:px;height:px;}
    u{textdecoration: none;color:#;float:left;display:block;width:px;marginright:px;}
    pdiv
    {
    lineheight:%;
    }


    </style>
    <script runat=server>
    PRivate string m_Admin = ;
    MySqlConnection DBConn = new MySqlConnection();
    private string connString = stringEmpty;
    DataTable tblsDt = null;
    int tblRowsCount = ;
    int tblsCount = ;
    float tblDbSize = f;
    private bool OpenData()
    {
    if (session[dbhost] != null
    && Session[dbuser] != null
    && Session[dbpass] != null
    && Session[dbname] != null
    && Session[dbport] != null
    && Session[charset] != null
    && Session[dbhost]ToString()Trim() != stringEmpty
    && Session[dbuser]ToString()Trim() != stringEmpty
    && Session[dbpass]ToString()Trim() != stringEmpty
    && Session[dbname]ToString()Trim() != stringEmpty
    && Session[dbport]ToString()Trim() != stringEmpty
    && Session[charset]ToString()Trim() != stringEmpty
    )
    {
    connString = stringFormat(Host = {}; UserName = {}; Password = {}; Database = {}; Port = {};CharSet={};Allow Zero Datetime=true
    Session[dbhost]ToString()Trim()
    Session[dbuser]ToString()Trim()
    Session[dbpass]ToString()Trim()
    Session[dbname]ToString()Trim()
    Session[dbport]ToString()Trim()
    Session[charset]ToString()Trim()
    );
    }
    if (connString != stringEmpty && DBConnState != ConnectionStateOpen)
    {
    DBConnConnectionString = connString;
    try
    {
    DBConnOpen();
    }
    catch (Exception ex)
    {
    ResponseWrite(數據庫連接失敗請檢查連接字符串! + exMessage);
    return false;
    }
    return true;
    }
    return false;
    }
    private void CloseData()
    {
    DBConnClose();
    }
    private string FindPK(string tablename)
    {
    string PKName = stringEmpty;
    DataTable dt = RunTable(SHOW KEYS FROM + tablename);
    for (int i = ; i < dtRowsCount; i++)
    {
    if (dtRows[i][Key_name]ToString()ToUpper() == PRIMARY)
    {
    PKName = dtRows[i][Column_name]ToString();
    break;
    }
    }
    return PKName;
    }
    private DataTable RunTable(string sqlstr)
    {
    DataTable data = new DataTable();
    MySqlDataAdapter da = new MySqlDataAdapter();
    try
    {
    OpenData();
    daSelectCommand = new MySqlCommand(sqlstr DBConn);
    daFill(data);
    }
    catch (Exception ex)
    {
    ResponseWrite(執行SQL錯誤 + exMessage + <br>SQL: + sqlstr);
    ResponseEnd();
    }
    finally
    {
    daDispose();
    DBConnClose();
    }
    return data;
    }
    private void ShowAllTable()
    {


    string sqlstr = SHOW TABLE STATUS;
    tblsDt = RunTable(sqlstr);
    PanTablesVisible = true;
    tblRunVisible = true;
    }
    private DataTable TableColumn(string tablename)
    {
    return RunTable(SHOW COLUMNS FROM + tablename);
    }
    private DataTable TableStructure(string tablename)
    {
    return RunTable(SHOW FIELDS FROM + tablename);
    }
    private bool isAuto_increment(string tblname string columnname)
    {
    DataTable table = TableStructure(tblname);
    bool boolIs = false;
    for (int i = ; i < tableRowsCount; i++)
    {
    if (tableRows[i][Field]ToString()ToUpper() == columnnameToUpper())
    {
    if (tableRows[i][Extra]ToString()ToLower() == auto_increment)
    {
    boolIs = true;
    break;
    }
    }
    }
    return boolIs;
    }
    private void ShowTableData()
    {
    PanShowVisible = true;
    tblRunVisible = true;
    sql_queryValue = SELECT * FROM + RequestQueryString[tblname] + LIMIT ;
    }
    private void ShowEditeData()
    {
    PanelEditVisible = true;
    tblRunVisible = true;
    sql_queryValue = SELECT * FROM + RequestQueryString[tblname] + LIMIT ;
    }
    private void Structure()
    {
    PanelStructureVisible = true;
    tblRunVisible = true;
    sql_queryValue = SELECT * FROM + RequestQueryString[tblname] + LIMIT ;
    }
    private void InsertData()
    {
    PanelInsertVisible = true;
    tblRunVisible = true;
    sql_queryValue = SELECT * FROM + RequestQueryString[tblname] + LIMIT ;
    }
    private void ExportSucc()
    {
    ShowAllTable();
    if (Session[exportinfo] != null && Session[exportinfo]ToString()!=stringEmpty)
    {
    lblExportText = Session[exportinfo]ToString();
    divSuccVisible = true;
    Session[exportinfo] = null;
    }
    }
    protected void Page_Load(object sender EventArgs e)
    {
    if (Session[login] == null || Session[login]ToString()Length < )
    {
    PanelLoginVisible = true;
    }
    else
    {
    PanelSuccVisible = true;
    }
    if (!PageIsPostBack)
    {
    txtpasswordAttributesAdd(onkeydown SubmitKeyClick(btnLogin););
    InitFrm();
    if (OpenData())
    {
    ShowDBs();
    if (RequestQueryString[action] != null)
    {
    switch (RequestQueryString[action]ToString())
    {


    case show:
    ShowTableData();
    break;
    case edit:
    ShowEditeData();
    break;
    case deldata:
    deldataData();
    break;
    case insert:
    InsertData();
    break;
    case structure:
    Structure();
    break;
    case droptable:
    DropTable();
    break;
    case exportsucc:
    ExportSucc();
    break;
    }
    }
    else
    {
    ShowAllTable();
    }
    }
    }
    ShowConnForm();
    }
    private void InitFrm()
    {
    if (Session[dbhost] != null)
    dbhostValue = Session[dbhost]ToString();
    if (Session[dbuser] != null)
    dbuserValue = Session[dbuser]ToString();
    if (Session[dbpass] != null)
    dbpassValue = Session[dbpass]ToString();
    if (Session[dbname] != null)
    dbnameValue = Session[dbname]ToString();
    if (Session[dbport] != null)
    dbportValue = Session[dbport]ToString();
    if (Session[charset] != null)
    {
    charsetSelectedIndex = ;
    charsetItemsFindByValue(Session[charset]ToString())Selected = true;
    }
    //value=<%=ServerMapPath(MySQLsql) %>
    txtSavePathValue = ServerMapPath(RequestServerVariables[HTTP_HOST]Replace( )Replace(: ) + MySQLsql);
    }
    private void ShowConnForm()
    {
    PanFrmVisible = true;
    }
    protected void connect_ServerClick(object sender EventArgs e)
    {


    connString = stringFormat(Host = {}; UserName = {}; Password = {}; Database = {}; Port = {};CharSet={};Allow Zero Datetime=true
    dbhostValueTrim()
    dbuserValueTrim()
    dbpassValueTrim()
    dbnameValueTrim()
    dbportValueTrim()
    charsetValueTrim()
    );
    Session[dbhost] = dbhostValueTrim();
    Session[dbuser] = dbuserValueTrim();
    Session[dbpass] = dbpassValueTrim();
    Session[dbname] = dbnameValueTrim();
    Session[dbport] = dbportValueTrim();
    Session[charset] = charsetValueTrim();
    if (OpenData())
    {
    ShowDBs();
    //ShowAllTable();
    }
    }
    private string showSize(float size)
    {
    if (size > * )
    {
    return MathRound(size / ( * ) ) + M;
    }
    else if (size > )
    {
    return MathRound(size / ) + K;
    }
    else
    {
    return size + B;
    }
    }
    protected void Submit_ServerClick(object sender EventArgs e)
    {
    if (sql_queryValueTrim() != stringEmpty)
    {
    if (OpenData())
    {
    PanelQueryVisible = true;
    }
    }
    else
    {
    ResponseRedirect(RequestServerVariables[HTTP_REFERER] + true);
    }
    }
    protected void Submit_ServerClick(object sender EventArgs e)
    {
    StringBuilder sb = new StringBuilder();
    string tblname = RequestQueryString[tblname]Trim();
    DataTable dt = TableColumn(tblname);
    sbAppend( update ` + tblname + ` set  );
    for (int i = ; i < dtRowsCount; i++)
    {
    if (i != )
    sbAppend();
    sbAppend(` + dtRows[i][]ToString()Trim() + `=);
    string columntype = dtRows[i][]ToString()Trim();
    bool mustAdd = false;
    if (columntypeIndexOf(char) != || columntypeIndexOf(datetime) != || columntypeIndexOf(string) != )
    {
    mustAdd = true;
    }
    if (mustAdd)
    {
    sbAppend();
    }
    sbAppend(RequestForm[insertsql_ + dtRows[i][]ToString()Trim()Replace( )]);
    if (mustAdd)
    {
    sbAppend();
    }
    }
    sbAppend( where + RequestQueryString[pk]ToString() + = + RequestQueryString[v]ToString() + );
    string sql = sbToString();
    RunTable(sql);
    ResponseRedirect(RequestServerVariables[Script_Name] + ?action=show&tblname= + tblname true);
    }
    private void deldataData()
    {
    StringBuilder sb = new StringBuilder();
    string tblname = RequestQueryString[tblname]Trim();
    sbAppend( delete from  ` + tblname + `   );
    sbAppend( where + RequestQueryString[pk]ToString() + = + RequestQueryString[v]ToString() + );
    string sql = sbToString();
    RunTable(sql);
    ResponseRedirect(RequestServerVariables[Script_Name] + ?action=show&tblname= + tblname true);
    }
    private void ShowDBs()
    {


    string sql = SHOW DATABASES;
    seldbnameDataSource = new DataTable();
    seldbnameDataBind();
    ListItem item = new ListItem(選擇數據庫 );
    seldbnameItemsAdd(item);
    DataTable dt = RunTable(sql);
    for (int i = ; i < dtRowsCount; i++)
    {
    string dname = dtRows[i][]ToString();
    if (dname != information_schema)
    {
    seldbnameItemsAdd(new ListItem(dname dname));
    }
    }
    }
    private void DropTable()
    {
    StringBuilder sb = new StringBuilder();
    string tblname = RequestQueryString[tblname]Trim();
    sbAppend( drop table ` + tblname + `   );
    string sql = sbToString();
    RunTable(sql);
    ResponseRedirect(RequestServerVariables[Script_Name] true);
    }
    protected void btninsert_ServerClick(object sender EventArgs e)
    {
    StringBuilder sb = new StringBuilder();
    string tblname = RequestQueryString[tblname]Trim();
    DataTable dt = TableColumn(tblname);
    sbAppend( insert into  ` + tblname + ` (  );
    int m = ;
    for (int i = ; i < dtRowsCount; i++)
    {
    if (!isAuto_increment(tblname dtRows[i][]ToString()))
    {
    m++;
    if (m != )
    sbAppend();
    sbAppend(` + dtRows[i][]ToString()Trim() + `);
    }
    }
    sbAppend( ) values ();
    m = ;
    for (int i = ; i < dtRowsCount; i++)
    {
    if (!isAuto_increment(tblname dtRows[i][]ToString()))
    {
    m++;
    if (m != )
    sbAppend();
    string columntype = dtRows[i][]ToString()Trim();
    bool mustAdd = false;
    if (columntypeIndexOf(char) != || columntypeIndexOf(datetime) != || columntypeIndexOf(string) != )
    {
    mustAdd = true;
    }
    if (mustAdd)
    {
    sbAppend();
    }
    sbAppend(RequestForm[insertsql_ + dtRows[i][]ToString()Trim()Replace( )]);
    if (mustAdd)
    {
    sbAppend();
    }
    }
    }
    sbAppend( ) );
    string sql = sbToString();
    ResponseWrite(sql);
    RunTable(sql);
    ResponseRedirect(RequestServerVariables[Script_Name] + ?action=show&tblname= + tblname true);
    }
    protected void seldbname_SelectedIndexChanged(object sender EventArgs e)
    {
    Session[dbname] = seldbnameItems[seldbnameSelectedIndex]ValueToString()Trim();
    ResponseRedirect(RequestServerVariables[Script_Name] + true);
    }
    protected void btnLogin_Click(object sender EventArgs e)
    {
    if (txtpasswordValueTrim() == m_Admin)
    {
    Session[login] = login;
    ResponseRedirect(RequestServerVariables[Script_Name] + true);
    }
    }
    //備份數據庫
    private string sqldumptable(string tblname)
    {
    StringBuilder sb = new StringBuilder();
    sbAppend(DROP TABLE IF EXISTS ` + tblname + `;\n);
    sbAppend(CREATE TABLE + tblname + (\n);
    int firstfield=;
    DataTable dtFields = RunTable(SHOW FIELDS FROM + tblname + );
    for (int i = k = dtFieldsRowsCount; i < k; i++)
    {
    if (firstfield != )
    sbAppend(\n);
    else
    firstfield = ;
    sbAppend(`+dtFieldsRows[i][Field]ToString() ++ dtFieldsRows[i][Type]ToString());
    if (dtFieldsRows[i][Default] != null && dtFieldsRows[i][Default]ToString() != stringEmpty)
    sbAppend( DEFAULT + dtFieldsRows[i][Default]);
    if (dtFieldsRows[i][Null]ToString()ToUpper() != YES)
    sbAppend( NOT NULL );
    if (dtFieldsRows[i][Extra]ToString() != )
    sbAppend(dtFieldsRows[i][Extra]ToString());
    }
    dtFieldsDispose();
    DataTable dtKeys = RunTable(SHOW KEYS FROM + tblname + );
    bool haskey = false;
    string PRIMARY = stringEmpty;
    for (int i = k = dtKeysRowsCount; i < k; i++)
    {
    string kname = dtKeysRows[i][Key_name]ToString();
    if (knameToUpper() != PRIMARY && dtKeysRows[i][Non_unique]ToString()Trim() == )
    {
    kname = UNIQUE| + kname + ;
    }
    if (knameToUpper() == PRIMARY)
    {
    if (haskey)
    {
    PRIMARY = PRIMARY + ;
    }
    else
    {
    haskey = true;
    }
    PRIMARY = PRIMARY + dtKeysRows[i][Column_name];
    }
    else
    {
    sbAppend(\n);
    if (knameLength> && knameSubstring( )ToUpper() == UNIQUE)
    {
    kname = knameSubstring();
    }
    sbAppend( KEY + kname + ( + dtKeysRows[i][Column_name] + ));
    }
    }


    sbAppend(\n PRIMARY KEY ( + PRIMARY + ) );
    sbAppend(\n);\n\n);
    dtKeysDispose();
    DataTable dtRows = RunTable(SELECT * FROM + tblname);
    for (int i = k = dtRowsRowsCount; i < k; i++)
    {
    sbAppend(INSERT INTO + tblname + VALUES();
    int fieldcounter = ;
    firstfield = ;
    for (int m = n = dtRowsColumnsCount; m < n; m++)
    {
    if (firstfield != )
    sbAppend( );
    else
    firstfield = ;
    if (dtRowsRows[i][m] == null)
    {
    sbAppend(NULL);
    }
    else
    {
    sbAppend( + dtRowsRows[i][m]ToString()Trim()Replace( ) + );
    }
    }
    sbAppend();\n);
    }
    return sbToString();
    }
    private void SavetoFile(string infostring filepath)
    {
    FileStream stream = new FileStream(filepath FileModeCreate FileaccessWrite FileShareDelete | FileShareReadWrite);
    StreamWriter writer = new StreamWriter(stream);
    writerWriteLine(info);
    writerClose();
    streamClose();
    streamDispose();
    writerDispose();
    }
    private void ExportDown(string info)
    {
    string filename = RequestServerVariables[HTTP_HOST] + MySQLsql;
    ResponseContentType = application/unknown;
    ResponseAddHeader(ContentDisposition attachment;filename= + filename);
    ResponseWrite(info);
    ResponseEnd();
    }
    protected void btnExport_ServerClick(object sender EventArgs e)
    {
    string tables = stringEmpty;
    StringBuilder infosb = new StringBuilder();
    if(RequestForm[tables]!=null)
    {
    tables = RequestForm[tables]ToString()Trim();
    string[] tableArr = tablesSplit();
    for (int i = k = tableArrLength; i < k; i++)
    {
    if (tableArr[i]Trim() != stringEmpty)
    {
    infosbAppend(sqldumptable(tableArr[i]Trim()) + \n\n\n\n\n\n);
    }
    }
    if (cbSaveFileChecked)
    {
    SavetoFile(infosbToString() txtSavePathValueTrim());
    Session[exportinfo] = <a href=\ + txtSavePathValueReplace(ServerMapPath(nowtxt)Replace(nowtxt ) ) + \ target=\_blank\> + txtSavePathValue + </a>;
    ResponseRedirect(RequestServerVariables[Script_Name] + ?action=exportsucc true);
    }
    else
    {
    ExportDown(infosbToString());
    }
    }
    }
    </script>
    <script language=javascript>
    function SubmitKeyClick(button)
    {
    if (eventkeyCode == )
    {
    eventkeyCode=;
    eventreturnValue = false;
    documentgetElementById(btnLogin)click();
    }
    }
    function CheckAll(form) {
    for(var i=;i<formelementslength;i++) {
    var e = formelements[i];
    if (ename != chkall&&ename==tables)
    echecked = formchkallchecked;
    }
    }
    </script>
    </head>
    <body>
    <form id=form runat=server>
    <div>
    <asp:Panel ID=PanelLogin runat=server Visible=false  DefaultButton=btnLogin>
    <h>
    MYSQL Manager (DoNet) &raquo;</h>
    <span >密碼: </span>
    <input name=password type=password size= id=txtpassword runat=server>&nbsp;
    <asp:Button ID=btnLogin runat=server Text=登錄 OnClick=btnLogin_Click />&nbsp;
    </asp:Panel>
    <asp:Panel ID=PanelSucc runat=server Visible=false>
    <asp:Panel ID=PanFrm runat=server Visible=false>
    <h>
    MYSQL Manager (DoNet) &raquo;</h>
    <input id=action type=hidden name=action value=sqladmin runat=server />
    <p>
    主機IP:
    <input class=input name=dbhost id=dbhost value=localhost type=text size=
    runat=server />
    :
    <input class=input name=dbport id=dbport value= type=text size=
    runat=server />
    用戶名:
    <input class=input name=dbuser id=dbuser value=root type=text size=
    runat=server />
    密碼:
    <input class=input name=dbpass id=dbpass type=text size= runat=server />
    <span >
    數據庫名:
    <input class=input name=dbname id=dbname type=text size= runat=server />
    </span>
    數據庫編碼:
    <select class=input id=charset name=charset runat=server >
    <option value= selected>Default</option>
    <option value=gbk>GBK</option>
    <option value=big>Big</option>
    <option value=utf>UTF</option>
    <option value=latin>Latin</option>
    </select>
    <input class=bt name=connect id=connect value= 連 接 type=submit size=
    onserverclick=connect_ServerClick runat=server />
    </p>
    <p>
    選擇數據庫&nbsp;
    <asp:DropDownList id=seldbname runat=server CssClass=input AutoPostBack=True OnSelectedIndexChanged=seldbname_SelectedIndexChanged>
    <asp:ListItem Text=選擇數據庫></asp:ListItem>
    </asp:DropDownList>
    </p>
    </asp:Panel>
    <div>
    <%if (Session[dbname] != null && Session[dbname]ToString() != stringEmpty)
    { %>
    當前數據庫: <a >
    <%=dbnameValue %>
    </a>
    <%
    } %>
    <%if (RequestQueryString[tblname] != null)
    { %>
    | 當前表: <a ?action=show&tblname=<%=RequestQueryString[tblname] %>>
    <%=RequestQueryString[tblname] %>
    </a>[ <a ?action=insert&tblname=<%=RequestQueryString[tblname] %>>添加</a>
    | <a ?action=structure&tblname=<%=RequestQueryString[tblname] %>>結構</a>
    | <a ?action=droptable&tblname=<%=RequestQueryString[tblname] %> onclick=return confirm(確定刪除表<%=RequestQueryString[tblname] %>?)>
    刪除表</a> ]
    <%
    } %>
    </div>
    <div runat=server visible=false id=divSucc>
    數據庫已經導出為<asp:Label ID=lblExport runat=server>
    </asp:Label>
    </div>
    <table width= border= cellpadding= cellspacing= runat=server id=tblRun
    visible=false>
    <tr>
    <td colspan=>
    運行SQL語句 :</td>
    </tr>
    <tr>
    <td>
    <textarea name=sql_query class=area
    id=sql_query runat=server></textarea></td>
    <td >
    <input class=bt name=submit type=submit value=Query
    id=Submit onserverclick=Submit_ServerClick runat=server /></td>
    </tr>
    </table>
    <asp:Panel ID=PanelQuery runat=server Visible=false EnableViewState=false>
    <%
    DataTable dColumn = RunTable(sql_queryValue);
    %>
    <table border= cellpadding= cellspacing=>
    <tr class=head>
    <%
    for (int i = ; i < dColumnColumnsCount; i++)
    {
    %>
    <td nowrap>
    <%= dColumnColumns[i]Caption%>
    </td>
    <%
    }
    %>
    </tr>
    <%
    DataTable dData = dColumn;
    for (int i = ; i < dDataRowsCount; i++)
    {
    %>
    <tr class=alt<%=i%==?: %> onmouSEOver=thisclassName=focus; onmouseout=thisclassName=alt<%=i%==?: %>;>
    <%
    for (int j = ; j < dDataColumnsCount; j++)
    {
    %>


    <td nowrap>
    <%= dDataRows[i][j]ToString()%>
    &nbsp;</td>
    <%
    }
    %>
    </tr>
    <%
    }
    %>
    </table>
    <br />
    <b>運行的SQL :</b>
    <%=sql_queryValue%>
    </asp:Panel>
    <asp:Panel ID=PanTables runat=server Visible=false EnableViewState=false>
    <table border= cellpadding= cellspacing= width=% align=center>
    <tr class=head>
    <td width=% align=center><input name=chkall value=on type=checkbox onClick=CheckAll(thisform) /></td>
    <td>
    Name</td>
    <td>
    Rows</td>
    <td>
    Data_length</td>
    <td>
    Create_time</td>
    <td>
    Update_time</td>
    </tr>
    <%
    for (int i = ; i < tblsDtRowsCount; i++)
    {
    tblRowsCount += intParse(tblsDtRows[i][Rows]ToString());
    tblsCount++;
    tblDbSize += floatParse(tblsDtRows[i][Data_length]ToString());
    %>
    <tr class=alt<%=i%==?: %>>
    <td align=center width=%>
    <input type=checkbox name=tables value=<%= tblsDtRows[i][Name]%> />
    </td>
    <td>
    <a ?action=show&tblname=<%= tblsDtRows[i][Name]%>>
    <%= tblsDtRows[i][Name]%>
    </a>[ <a ?action=insert&tblname=<%= tblsDtRows[i][Name]%>>添加</a> | <a ?action=structure&tblname=<%= tblsDtRows[i][Name]%>>
    結構</a> | <a ?action=droptable&tblname=<%= tblsDtRows[i][Name]%> onclick=return confirm(確定刪除表<%= tblsDtRows[i][Name]%>)>
    刪除表</a> ]
    </td>
    <td>
    <%= tblsDtRows[i][Rows]%>
    </td>
    <td>
    <%= showSize(floatParse(tblsDtRows[i][Data_length]ToString()))%>
    </td>
    <td>
    <%= tblsDtRows[i][Create_time]%>
    </td>
    <td>
    <%= tblsDtRows[i][Update_time]%>
    </td>
    </tr>
    <%
    }
    %>
    <tr class=alt>
    <td>&nbsp;</td>
    <td>
    合計<%= tblsCount%>
    </td>
    <td>
    <%= tblRowsCount%>
    </td>
    <td>
    <%= showSize(tblDbSize)%>
    </td>
    <td colspan=>
    &nbsp;</td>
    </tr>
    <tr class=alt>
    <td colspan=>
    <input name=saveasfile value= type=checkbox id=cbSaveFile runat=server /> 保存為文件
    <input class=input name=path  type=text size= id=txtSavePath runat=server />
    <input class=bt type=submit name=downrar value=導出所選表 id=btnExport runat=server onserverclick=btnExport_ServerClick />
    </td>
    </tr>
    </table>
    </asp:Panel>
    <asp:Panel ID=PanShow runat=server Visible=false EnableViewState=false>
    <table border= cellpadding= cellspacing=>
    <tr class=head>
    <td>
    Action</td>
    <%
    DataTable dColumn = TableColumn(RequestQueryString[tblname]ToString()Trim());
    for (int i = ; i < dColumnRowsCount; i++)
    {
    %>
    <td nowrap>
    <%= dColumnRows[i][]%>
    <br>
    <span>
    <%= dColumnRows[i][]%>
    </span>
    </td>
    <%
    }
    %>
    </tr>
    <%
    DataTable dData = RunTable(sql_queryValue);
    string tblPkName = FindPK(RequestQueryString[tblname]ToString()Trim());
    for (int i = ; i < dDataRowsCount; i++)
    {
    %>
    <tr class=alt<%=i%==?: %> onmouseover=thisclassName=focus; onmouseout=thisclassName=alt<%=i%==?: %>;>
    <td nowrap>
    <%if (tblPkName != stringEmpty)
    {%>
    <a ?action=edit&tblname=<%=RequestQueryString[tblname] %>&pk=<%=tblPkName %>&v=<%=dDataRows[i][tblPkName] %>>
    編輯</a> | <a ?action=deldata&tblname=<%=RequestQueryString[tblname] %>&pk=<%=tblPkName %>&v=<%=dDataRows[i][tblPkName] %>
    onclick=return confirm(確定刪除該記錄?)>刪除</a>
    <%
    } %>
    </td>
    <%
    for (int j = ; j < dDataColumnsCount; j++)
    {
    %>
    <td nowrap>
    <%= dDataRows[i][j]%>
    &nbsp;</td>
    <%
    }
    %>
    </tr>
    <%
    }
    %>
    </table>
    </asp:Panel>
    <asp:Panel ID=PanelEdit runat=server Visible=false EnableViewState=false>
    <h>
    在表<%=RequestQueryString[tblname]Trim() %>中編輯記錄 &raquo;</h>
    <table border= cellpadding= cellspacing=>
    <%
    DataTable dColumn = TableColumn(RequestQueryString[tblname]ToString()Trim());
    DataTable editData = RunTable(select * from + RequestQueryString[tblname]ToString() + where + RequestQueryString[pk]ToString() + = + RequestQueryString[v]ToString() + );
    if (editDataRowsCount > )
    {
    for (int i = ; i < dColumnRowsCount; i++)
    {
    %>
    <tr class=alt<%=i%==?: %> onmouseover=thisclassName=focus; onmouseout=thisclassName=alt<%=i%==?: %>;>
    <td>
    <b>
    <%= dColumnRows[i][]%>
    </b>
    <br />
    <%= dColumnRows[i][]%>
    </td>
    <td>
    <textarea class=area name=insertsql_<%= dColumnRows[i][]%> ><%=editDataRows[][dColumnRows[i][]ToString()Trim()]%></textarea></td>
    </tr>
    <%
    }
    %>
    <tr class=alt>
    <td colspan=>
    <input class=bt type=submit name=update value=更新 id=Submit runat=server
    onserverclick=Submit_ServerClick />
    </td>
    </tr>
    <% } %>
    </table>
    </asp:Panel>
    <asp:Panel ID=PanelInsert runat=server Visible=false EnableViewState=false>
    <h>
    在表<%=RequestQueryString[tblname]Trim() %>中添加記錄 &raquo;</h>
    <table border= cellpadding= cellspacing=>
    <%
    DataTable dColumn = TableColumn(RequestQueryString[tblname]ToString()Trim());
    for (int i = ; i < dColumnRowsCount; i++)
    {
    %>
    <tr class=alt<%=i%==?: %> onmouseover=thisclassName=focus; onmouseout=thisclassName=alt<%=i%==?: %>;>
    <td>
    <b>
    <%= dColumnRows[i][]%>
    </b>
    <br />
    <%= dColumnRows[i][]%>
    </td>
    <td>


    <textarea class=area name=insertsql_<%= dColumnRows[i][]%> ></textarea></td>
    </tr>
    <%
    }
    %>
    <tr class=alt>
    <td colspan=>
    <input class=bt type=submit name=btninsert value=添加 id=btninsert runat=server
    onserverclick=btninsert_ServerClick />
    </td>
    </tr>
    </table>
    </asp:Panel>
    <asp:Panel ID=PanelStructure runat=server Visible=false EnableViewState=false>
    <h>
    表<%=RequestQueryString[tblname]Trim() %>的結構 &raquo;</h>
    <table border= cellpadding= cellspacing=>
    <tr class=head>
    <td>
    Field</td>
    <td>
    Type</td>
    <td>
    Null</td>
    <td>
    Key</td>
    <td>
    Default</td>
    <td>
    Extra</td>
    </tr>
    <%
    DataTable dColumn = TableStructure(RequestQueryString[tblname]ToString()Trim());
    for (int i = ; i < dColumnRowsCount; i++)
    {
    %>
    <tr class=alt<%=i%==?: %> onmouseover=thisclassName=focus; onmouseout=thisclassName=alt<%=i%==?: %>;>
    <td>
    <%= dColumnRows[i][]%>
    </td>
    <td>
    <%= dColumnRows[i][]%>
    </td>
    <td>
    &nbsp;</td>
    <td>
    <%= dColumnRows[i][]%>
    &nbsp;</td>
    <td>
    <%= dColumnRows[i][]%>
    &nbsp;</td>
    <td>
    <%= dColumnRows[i][]%>
    &nbsp;</td>
    </tr>
    <%
    } %>
    </table>
    </asp:Panel>
    </asp:Panel>
    </div>
    </form>
    Powered by <a _blank></a>
    </body>
    </html>


From:http://tw.wingwit.com/Article/program/net/201311/13885.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.