在 中
可以通過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
;
DBConn
ConnectionString = connString;
DBConn
Open();
二
執行sql命令
string sqlstr=
select * from test
;
MySqlCommand command = new MySqlCommand(sqlstr
DBConn);
command
ExecuteNonQuery();
從上面可以看出
用法跟操作SQL數據庫的SqlConnection
SqlCommand非常相似
下面我這裡有一個完整的例子來實現對mysql數據庫進行管理
包括浏覽表結構和數據
查詢
修改
插入
刪除數據
導出數據和表結構等
供大家參考和互相學習
代碼寫得不規范
還請大家指正
<%@ Page Language=
C#
%>
<%@ Import Namespace=
System
Data
%>
<%@ Import Namespace=
System
IO
%>
<%@ Import Namespace=
System
Text
%>
<%@ Import Namespace=
MySql
Data
MySqlClient
%>
<!DOCTYPE html PUBLIC
//W
C//DTD XHTML
Transitional//EN
transitional
dtd
>
<html xmlns=
>
<head runat=
server
>
<title> MYSQL Manager (DoNet)</title>
<style type=
text/CSS
>
body
td{font:
px Arial
Tahoma;line
height:
px;}
input{font:
px Arial
Tahoma;background:#fff;border:
px solid #
;padding:
px;height:
px;}
area{font:
px
Courier New
Monospace;background:#fff;border:
px solid #
;padding:
px;}
bt {border
color:#b
b
b
;background:#
d
d
d;color:#ffffff;font:
px Arial
Tahoma;height:
px;}
a {color: #
f;text
decoration:underline;}
a:hover{color: #f
;text
decoration:none;}
alt
td{border
top:
px solid #fff;border
bottom:
px solid #ddd;background:#f
f
f
;padding:
px
px
px
px;}
alt
td{border
top:
px solid #fff;border
bottom:
px solid #ddd;background:#f
f
f
;padding:
px
px
px
px;}
focus td{border
top:
px solid #fff;border
bottom:
px solid #ddd;background:#ffffaa;padding:
px
px
px
px;}
head td{border
top:
px solid #fff;border
bottom:
px solid #ddd;background:#e
e
e
;padding:
px
px
px
px;font
weight:bold;}
head td span{font
weight:normal;}
form{margin:
;padding:
;}
h
{margin:
;padding:
;height:
px;line
height:
px;font
size:
px;color:#
B
F;}
li{margin:
;color:#
;line
height:
px;height:
px;}
u{text
decoration: none;color:#
;float:left;display:block;width:
px;margin
right:
px;}
p
div
{
line
height:
%;
}
</style>
<script runat=
server
>
PRivate string m_Admin =
;
MySqlConnection DBConn = new MySqlConnection();
private string connString = string
Empty;
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() != string
Empty
&& Session[
dbuser
]
ToString()
Trim() != string
Empty
&& Session[
dbpass
]
ToString()
Trim() != string
Empty
&& Session[
dbname
]
ToString()
Trim() != string
Empty
&& Session[
dbport
]
ToString()
Trim() != string
Empty
&& Session[
charset
]
ToString()
Trim() != string
Empty
)
{
connString = string
Format(
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 != string
Empty && DBConn
State != ConnectionState
Open)
{
DBConn
ConnectionString = connString;
try
{
DBConn
Open();
}
catch (Exception ex)
{
Response
Write(
數據庫連接失敗
請檢查連接字符串!
+ ex
Message);
return false;
}
return true;
}
return false;
}
private void CloseData()
{
DBConn
Close();
}
private string FindPK(string tablename)
{
string PKName = string
Empty;
DataTable dt = RunTable(
SHOW KEYS FROM
+ tablename);
for (int i =
; i < dt
Rows
Count; i++)
{
if (dt
Rows[i][
Key_name
]
ToString()
ToUpper() ==
PRIMARY
)
{
PKName = dt
Rows[i][
Column_name
]
ToString();
break;
}
}
return PKName;
}
private DataTable RunTable(string sqlstr)
{
DataTable data = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter();
try
{
OpenData();
da
SelectCommand = new MySqlCommand(sqlstr
DBConn);
da
Fill(data);
}
catch (Exception ex)
{
Response
Write(
執行SQL錯誤
+ ex
Message +
<br>SQL:
+ sqlstr);
Response
End();
}
finally
{
da
Dispose();
DBConn
Close();
}
return data;
}
private void ShowAllTable()
{
string sqlstr =
SHOW TABLE STATUS
;
tblsDt = RunTable(sqlstr);
PanTables
Visible = true;
tblRun
Visible = 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 < table
Rows
Count; i++)
{
if (table
Rows[i][
Field
]
ToString()
ToUpper() == columnname
ToUpper())
{
if (table
Rows[i][
Extra
]
ToString()
ToLower() ==
auto_increment
)
{
boolIs = true;
break;
}
}
}
return boolIs;
}
private void ShowTableData()
{
PanShow
Visible = true;
tblRun
Visible = true;
sql_query
Value =
SELECT * FROM
+ Request
QueryString[
tblname
] +
LIMIT
;
}
private void ShowEditeData()
{
PanelEdit
Visible = true;
tblRun
Visible = true;
sql_query
Value =
SELECT * FROM
+ Request
QueryString[
tblname
] +
LIMIT
;
}
private void Structure()
{
PanelStructure
Visible = true;
tblRun
Visible = true;
sql_query
Value =
SELECT * FROM
+ Request
QueryString[
tblname
] +
LIMIT
;
}
private void InsertData()
{
PanelInsert
Visible = true;
tblRun
Visible = true;
sql_query
Value =
SELECT * FROM
+ Request
QueryString[
tblname
] +
LIMIT
;
}
private void ExportSucc()
{
ShowAllTable();
if (Session[
exportinfo
] != null && Session[
exportinfo
]
ToString()!=string
Empty)
{
lblExport
Text = Session[
exportinfo
]
ToString();
divSucc
Visible = true;
Session[
exportinfo
] = null;
}
}
protected void Page_Load(object sender
EventArgs e)
{
if (Session[
login
] == null || Session[
login
]
ToString()
Length <
)
{
PanelLogin
Visible = true;
}
else
{
PanelSucc
Visible = true;
}
if (!Page
IsPostBack)
{
txtpassword
Attributes
Add(
onkeydown
SubmitKeyClick(
btnLogin
);
);
InitFrm();
if (OpenData())
{
ShowDBs();
if (Request
QueryString[
action
] != null)
{
switch (Request
QueryString[
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)
dbhost
Value = Session[
dbhost
]
ToString();
if (Session[
dbuser
] != null)
dbuser
Value = Session[
dbuser
]
ToString();
if (Session[
dbpass
] != null)
dbpass
Value = Session[
dbpass
]
ToString();
if (Session[
dbname
] != null)
dbname
Value = Session[
dbname
]
ToString();
if (Session[
dbport
] != null)
dbport
Value = Session[
dbport
]
ToString();
if (Session[
charset
] != null)
{
charset
SelectedIndex =
;
charset
Items
FindByValue(Session[
charset
]
ToString())
Selected = true;
}
//value=
<%=Server
MapPath(
MySQL
sql
) %>
txtSavePath
Value = Server
MapPath(Request
ServerVariables[
HTTP_HOST
]
Replace(
)
Replace(
:
) +
MySQL
sql
);
}
private void ShowConnForm()
{
PanFrm
Visible = true;
}
protected void connect_ServerClick(object sender
EventArgs e)
{
connString = string
Format(
Host = {
}; UserName = {
}; Password = {
}; Database = {
}; Port = {
};CharSet={
};Allow Zero Datetime=true
dbhost
Value
Trim()
dbuser
Value
Trim()
dbpass
Value
Trim()
dbname
Value
Trim()
dbport
Value
Trim()
charset
Value
Trim()
);
Session[
dbhost
] = dbhost
Value
Trim();
Session[
dbuser
] = dbuser
Value
Trim();
Session[
dbpass
] = dbpass
Value
Trim();
Session[
dbname
] = dbname
Value
Trim();
Session[
dbport
] = dbport
Value
Trim();
Session[
charset
] = charset
Value
Trim();
if (OpenData())
{
ShowDBs();
//ShowAllTable();
}
}
private string showSize(float size)
{
if (size >
*
)
{
return Math
Round(size / (
*
)
) +
M
;
}
else if (size >
)
{
return Math
Round(size /
) +
K
;
}
else
{
return size +
B
;
}
}
protected void Submit
_ServerClick(object sender
EventArgs e)
{
if (sql_query
Value
Trim() != string
Empty)
{
if (OpenData())
{
PanelQuery
Visible = true;
}
}
else
{
Response
Redirect(Request
ServerVariables[
HTTP_REFERER
] +
true);
}
}
protected void Submit
_ServerClick(object sender
EventArgs e)
{
StringBuilder sb = new StringBuilder();
string tblname = Request
QueryString[
tblname
]
Trim();
DataTable dt = TableColumn(tblname);
sb
Append(
update `
+ tblname +
` set
);
for (int i =
; i < dt
Rows
Count; i++)
{
if (i !=
)
sb
Append(
);
sb
Append(
`
+ dt
Rows[i][
]
ToString()
Trim() +
`=
);
string columntype = dt
Rows[i][
]
ToString()
Trim();
bool mustAdd = false;
if (columntype
IndexOf(
char
) !=
|| columntype
IndexOf(
datetime
) !=
|| columntype
IndexOf(
string
) !=
)
{
mustAdd = true;
}
if (mustAdd)
{
sb
Append(
);
}
sb
Append(Request
Form[
insertsql_
+ dt
Rows[i][
]
ToString()
Trim()
Replace(
)]);
if (mustAdd)
{
sb
Append(
);
}
}
sb
Append(
where
+ Request
QueryString[
pk
]
ToString() +
=
+ Request
QueryString[
v
]
ToString() +
);
string sql = sb
ToString();
RunTable(sql);
Response
Redirect(Request
ServerVariables[
Script_Name
] +
?action=show&tblname=
+ tblname
true);
}
private void deldataData()
{
StringBuilder sb = new StringBuilder();
string tblname = Request
QueryString[
tblname
]
Trim();
sb
Append(
delete from `
+ tblname +
`
);
sb
Append(
where
+ Request
QueryString[
pk
]
ToString() +
=
+ Request
QueryString[
v
]
ToString() +
);
string sql = sb
ToString();
RunTable(sql);
Response
Redirect(Request
ServerVariables[
Script_Name
] +
?action=show&tblname=
+ tblname
true);
}
private void ShowDBs()
{
string sql =
SHOW DATABASES
;
seldbname
DataSource = new DataTable();
seldbname
DataBind();
ListItem item = new ListItem(
選擇數據庫
);
seldbname
Items
Add(item);
DataTable dt = RunTable(sql);
for (int i =
; i < dt
Rows
Count; i++)
{
string dname = dt
Rows[i][
]
ToString();
if (dname !=
information_schema
)
{
seldbname
Items
Add(new ListItem(dname
dname));
}
}
}
private void DropTable()
{
StringBuilder sb = new StringBuilder();
string tblname = Request
QueryString[
tblname
]
Trim();
sb
Append(
drop table `
+ tblname +
`
);
string sql = sb
ToString();
RunTable(sql);
Response
Redirect(Request
ServerVariables[
Script_Name
]
true);
}
protected void btninsert_ServerClick(object sender
EventArgs e)
{
StringBuilder sb = new StringBuilder();
string tblname = Request
QueryString[
tblname
]
Trim();
DataTable dt = TableColumn(tblname);
sb
Append(
insert into `
+ tblname +
` (
);
int m =
;
for (int i =
; i < dt
Rows
Count; i++)
{
if (!isAuto_increment(tblname
dt
Rows[i][
]
ToString()))
{
m++;
if (m !=
)
sb
Append(
);
sb
Append(
`
+ dt
Rows[i][
]
ToString()
Trim() +
`
);
}
}
sb
Append(
) values (
);
m =
;
for (int i =
; i < dt
Rows
Count; i++)
{
if (!isAuto_increment(tblname
dt
Rows[i][
]
ToString()))
{
m++;
if (m !=
)
sb
Append(
);
string columntype = dt
Rows[i][
]
ToString()
Trim();
bool mustAdd = false;
if (columntype
IndexOf(
char
) !=
|| columntype
IndexOf(
datetime
) !=
|| columntype
IndexOf(
string
) !=
)
{
mustAdd = true;
}
if (mustAdd)
{
sb
Append(
);
}
sb
Append(Request
Form[
insertsql_
+ dt
Rows[i][
]
ToString()
Trim()
Replace(
)]);
if (mustAdd)
{
sb
Append(
);
}
}
}
sb
Append(
)
);
string sql = sb
ToString();
Response
Write(sql);
RunTable(sql);
Response
Redirect(Request
ServerVariables[
Script_Name
] +
?action=show&tblname=
+ tblname
true);
}
protected void seldbname_SelectedIndexChanged(object sender
EventArgs e)
{
Session[
dbname
] = seldbname
Items[seldbname
SelectedIndex]
Value
ToString()
Trim();
Response
Redirect(Request
ServerVariables[
Script_Name
] +
true);
}
protected void btnLogin_Click(object sender
EventArgs e)
{
if (txtpassword
Value
Trim() == m_Admin)
{
Session[
login
] =
login
;
Response
Redirect(Request
ServerVariables[
Script_Name
] +
true);
}
}
//備份數據庫
private string sqldumptable(string tblname)
{
StringBuilder sb = new StringBuilder();
sb
Append(
DROP TABLE IF EXISTS `
+ tblname +
`;\n
);
sb
Append(
CREATE TABLE
+ tblname +
(\n
);
int firstfield=
;
DataTable dtFields = RunTable(
SHOW FIELDS FROM
+ tblname +
);
for (int i =
k = dtFields
Rows
Count; i < k; i++)
{
if (firstfield !=
)
sb
Append(
\n
);
else
firstfield =
;
sb
Append(
`
+dtFields
Rows[i][
Field
]
ToString() +
`
+ dtFields
Rows[i][
Type
]
ToString());
if (dtFields
Rows[i][
Default
] != null && dtFields
Rows[i][
Default
]
ToString() != string
Empty)
sb
Append(
DEFAULT
+ dtFields
Rows[i][
Default
]);
if (dtFields
Rows[i][
Null
]
ToString()
ToUpper() !=
YES
)
sb
Append(
NOT NULL
);
if (dtFields
Rows[i][
Extra
]
ToString() !=
)
sb
Append(dtFields
Rows[i][
Extra
]
ToString());
}
dtFields
Dispose();
DataTable dtKeys = RunTable(
SHOW KEYS FROM
+ tblname +
);
bool haskey = false;
string PRIMARY = string
Empty;
for (int i =
k = dtKeys
Rows
Count; i < k; i++)
{
string kname = dtKeys
Rows[i][
Key_name
]
ToString();
if (kname
ToUpper() !=
PRIMARY
&& dtKeys
Rows[i][
Non_unique
]
ToString()
Trim() ==
)
{
kname =
UNIQUE|
+ kname +
;
}
if (kname
ToUpper() ==
PRIMARY
)
{
if (haskey)
{
PRIMARY = PRIMARY +
;
}
else
{
haskey = true;
}
PRIMARY = PRIMARY + dtKeys
Rows[i][
Column_name
];
}
else
{
sb
Append(
\n
);
if (kname
Length>
&& kname
Substring(
)
ToUpper() ==
UNIQUE
)
{
kname = kname
Substring(
);
}
sb
Append(
KEY
+ kname +
(
+ dtKeys
Rows[i][
Column_name
] +
)
);
}
}
sb
Append(
\n PRIMARY KEY (
+ PRIMARY +
)
);
sb
Append(
\n);\n\n
);
dtKeys
Dispose();
DataTable dtRows = RunTable(
SELECT * FROM
+ tblname);
for (int i =
k = dtRows
Rows
Count; i < k; i++)
{
sb
Append(
INSERT INTO
+ tblname +
VALUES(
);
int fieldcounter =
;
firstfield =
;
for (int m =
n = dtRows
Columns
Count; m < n; m++)
{
if (firstfield !=
)
sb
Append(
);
else
firstfield =
;
if (dtRows
Rows[i][m] == null)
{
sb
Append(
NULL
);
}
else
{
sb
Append(
+ dtRows
Rows[i][m]
ToString()
Trim()
Replace(
) +
);
}
}
sb
Append(
);\n
);
}
return sb
ToString();
}
private void SavetoFile(string info
string filepath)
{
FileStream stream = new FileStream(filepath
FileMode
Create
Fileaccess
Write
FileShare
Delete | FileShare
ReadWrite);
StreamWriter writer = new StreamWriter(stream);
writer
WriteLine(info);
writer
Close();
stream
Close();
stream
Dispose();
writer
Dispose();
}
private void ExportDown(string info)
{
string filename = Request
ServerVariables[
HTTP_HOST
] +
MySQL
sql
;
Response
ContentType =
application/unknown
;
Response
AddHeader(
Content
Disposition
attachment;filename=
+ filename);
Response
Write(info);
Response
End();
}
protected void btnExport_ServerClick(object sender
EventArgs e)
{
string tables = string
Empty;
StringBuilder infosb = new StringBuilder();
if(Request
Form[
tables
]!=null)
{
tables = Request
Form[
tables
]
ToString()
Trim();
string[] tableArr = tables
Split(
);
for (int i =
k = tableArr
Length; i < k; i++)
{
if (tableArr[i]
Trim() != string
Empty)
{
infosb
Append(sqldumptable(tableArr[i]
Trim()) +
\n\n\n\n\n\n
);
}
}
if (cbSaveFile
Checked)
{
SavetoFile(infosb
ToString()
txtSavePath
Value
Trim());
Session[
exportinfo
] =
<a href=\
+ txtSavePath
Value
Replace(Server
MapPath(
now
txt
)
Replace(
now
txt
)
) +
\
target=\
_blank\
>
+ txtSavePath
Value +
</a>
;
Response
Redirect(Request
ServerVariables[
Script_Name
] +
?action=exportsucc
true);
}
else
{
ExportDown(infosb
ToString());
}
}
}
</script>
<script language=
javascript
>
function SubmitKeyClick(button)
{
if (event
keyCode ==
)
{
event
keyCode=
;
event
returnValue = false;
document
getElementById(
btnLogin
)
click();
}
}
function CheckAll(form) {
for(var i=
;i<form
elements
length;i++) {
var e = form
elements[i];
if (e
name !=
chkall
&&e
name==
tables
)
e
checked = form
chkall
checked;
}
}
</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() != string
Empty)
{ %>
當前數據庫: <a >
<%=dbname
Value %>
</a>
<%
} %>
<%if (Request
QueryString[
tblname
] != null)
{ %>
| 當前表: <a ?action=show&tblname=<%=Request
QueryString[
tblname
] %>
>
<%=Request
QueryString[
tblname
] %>
</a>[ <a ?action=insert&tblname=<%=Request
QueryString[
tblname
] %>
>添加</a>
| <a ?action=structure&tblname=<%=Request
QueryString[
tblname
] %>
>結構</a>
| <a ?action=droptable&tblname=<%=Request
QueryString[
tblname
] %>
onclick=
return confirm(
確定刪除表
<%=Request
QueryString[
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_query
Value);
%>
<table border=
cellpadding=
cellspacing=
>
<tr class=
head
>
<%
for (int i =
; i < dColumn
Columns
Count; i++)
{
%>
<td nowrap>
<%= dColumn
Columns[i]
Caption%>
</td>
<%
}
%>
</tr>
<%
DataTable dData = dColumn;
for (int i =
; i < dData
Rows
Count; i++)
{
%>
<tr class=
alt<%=i%
==
?
:
%>
onmouSEOver=
this
className=
focus
;
onmouseout=
this
className=
alt<%=i%
==
?
:
%>
;
>
<%
for (int j =
; j < dData
Columns
Count; j++)
{
%>
<td nowrap>
<%= dData
Rows[i][j]
ToString()%>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
<br />
<b>運行的SQL :</b>
<%=sql_query
Value%>
</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(this
form)
/></td>
<td>
Name</td>
<td>
Rows</td>
<td>
Data_length</td>
<td>
Create_time</td>
<td>
Update_time</td>
</tr>
<%
for (int i =
; i < tblsDt
Rows
Count; i++)
{
tblRowsCount += int
Parse(tblsDt
Rows[i][
Rows
]
ToString());
tblsCount++;
tblDbSize += float
Parse(tblsDt
Rows[i][
Data_length
]
ToString());
%>
<tr class=
alt<%=i%
==
?
:
%>
>
<td align=
center
width=
%
>
<input type=
checkbox
name=
tables
value=
<%= tblsDt
Rows[i][
Name
]%>
/>
</td>
<td>
<a ?action=show&tblname=<%= tblsDt
Rows[i][
Name
]%>
>
<%= tblsDt
Rows[i][
Name
]%>
</a>[ <a ?action=insert&tblname=<%= tblsDt
Rows[i][
Name
]%>
>添加</a> | <a ?action=structure&tblname=<%= tblsDt
Rows[i][
Name
]%>
>
結構</a> | <a ?action=droptable&tblname=<%= tblsDt
Rows[i][
Name
]%>
onclick=
return confirm(
確定刪除表
<%= tblsDt
Rows[i][
Name
]%>
?
)
>
刪除表</a> ]
</td>
<td>
<%= tblsDt
Rows[i][
Rows
]%>
</td>
<td>
<%= showSize(float
Parse(tblsDt
Rows[i][
Data_length
]
ToString()))%>
</td>
<td>
<%= tblsDt
Rows[i][
Create_time
]%>
</td>
<td>
<%= tblsDt
Rows[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(Request
QueryString[
tblname
]
ToString()
Trim());
for (int i =
; i < dColumn
Rows
Count; i++)
{
%>
<td nowrap>
<%= dColumn
Rows[i][
]%>
<br>
<span>
<%= dColumn
Rows[i][
]%>
</span>
</td>
<%
}
%>
</tr>
<%
DataTable dData = RunTable(sql_query
Value);
string tblPkName = FindPK(Request
QueryString[
tblname
]
ToString()
Trim());
for (int i =
; i < dData
Rows
Count; i++)
{
%>
<tr class=
alt<%=i%
==
?
:
%>
onmouseover=
this
className=
focus
;
onmouseout=
this
className=
alt<%=i%
==
?
:
%>
;
>
<td nowrap>
<%if (tblPkName != string
Empty)
{%>
<a ?action=edit&tblname=<%=Request
QueryString[
tblname
] %>&pk=<%=tblPkName %>&v=<%=dData
Rows[i][tblPkName] %>
>
編輯</a> | <a ?action=deldata&tblname=<%=Request
QueryString[
tblname
] %>&pk=<%=tblPkName %>&v=<%=dData
Rows[i][tblPkName] %>
onclick=
return confirm(
確定刪除該記錄?
)
>刪除</a>
<%
} %>
</td>
<%
for (int j =
; j < dData
Columns
Count; j++)
{
%>
<td nowrap>
<%= dData
Rows[i][j]%>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
</asp:Panel>
<asp:Panel ID=
PanelEdit
runat=
server
Visible=
false
EnableViewState=
false
>
<h
>
在表<%=Request
QueryString[
tblname
]
Trim() %>中編輯記錄 »</h
>
<table border=
cellpadding=
cellspacing=
>
<%
DataTable dColumn = TableColumn(Request
QueryString[
tblname
]
ToString()
Trim());
DataTable editData = RunTable(
select * from
+ Request
QueryString[
tblname
]
ToString() +
where
+ Request
QueryString[
pk
]
ToString() +
=
+ Request
QueryString[
v
]
ToString() +
);
if (editData
Rows
Count >
)
{
for (int i =
; i < dColumn
Rows
Count; i++)
{
%>
<tr class=
alt<%=i%
==
?
:
%>
onmouseover=
this
className=
focus
;
onmouseout=
this
className=
alt<%=i%
==
?
:
%>
;
>
<td>
<b>
<%= dColumn
Rows[i][
]%>
</b>
<br />
<%= dColumn
Rows[i][
]%>
</td>
<td>
<textarea class=
area
name=
insertsql_<%= dColumn
Rows[i][
]%>
><%=editData
Rows[
][dColumn
Rows[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
>
在表<%=Request
QueryString[
tblname
]
Trim() %>中添加記錄 »</h
>
<table border=
cellpadding=
cellspacing=
>
<%
DataTable dColumn = TableColumn(Request
QueryString[
tblname
]
ToString()
Trim());
for (int i =
; i < dColumn
Rows
Count; i++)
{
%>
<tr class=
alt<%=i%
==
?
:
%>
onmouseover=
this
className=
focus
;
onmouseout=
this
className=
alt<%=i%
==
?
:
%>
;
>
<td>
<b>
<%= dColumn
Rows[i][
]%>
</b>
<br />
<%= dColumn
Rows[i][
]%>
</td>
<td>
<textarea class=
area
name=
insertsql_<%= dColumn
Rows[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
>
表<%=Request
QueryString[
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(Request
QueryString[
tblname
]
ToString()
Trim());
for (int i =
; i < dColumn
Rows
Count; i++)
{
%>
<tr class=
alt<%=i%
==
?
:
%>
onmouseover=
this
className=
focus
;
onmouseout=
this
className=
alt<%=i%
==
?
:
%>
;
>
<td>
<%= dColumn
Rows[i][
]%>
</td>
<td>
<%= dColumn
Rows[i][
]%>
</td>
<td>
</td>
<td>
<%= dColumn
Rows[i][
]%>
</td>
<td>
<%= dColumn
Rows[i][
]%>
</td>
<td>
<%= dColumn
Rows[i][
]%>
</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