在 中
可以通过MySQL
Data
dll来操作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) »</h>
<span >密码: </span>
<input name=password type=password size= id=txtpassword runat=server>
<asp:Button ID=btnLogin runat=server Text=登录 OnClick=btnLogin_Click />
</asp:Panel>
<asp:Panel ID=PanelSucc runat=server Visible=false>
<asp:Panel ID=PanFrm runat=server Visible=false>
<h>
MYSQL Manager (DoNet) »</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>
选择数据库
<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()%>
</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> </td>
<td>
合计<%= tblsCount%>
</td>
<td>
<%= tblRowsCount%>
</td>
<td>
<%= showSize(tblDbSize)%>
</td>
<td colspan=>
</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]%>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
</asp:Panel>
<asp:Panel ID=PanelEdit runat=server Visible=false EnableViewState=false>
<h>
在表<%=RequestQueryString[tblname]Trim() %>中编辑记录 »</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() %>中添加记录 »</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() %>的结构 »</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>
</td>
<td>
<%= dColumnRows[i][]%>
</td>
<td>
<%= dColumnRows[i][]%>
</td>
<td>
<%= dColumnRows[i][]%>
</td>
</tr>
<%
} %>
</table>
</asp:Panel>
</asp:Panel>
</div>
</form>
Powered by <a _blank></a>
</body>
</html>