±NSQL¬d¸ß¥X¨Óªºµ²ªGÅã¥Ü¦b¬Yºô¶¤W?
- ©«¤l
- 8
- ¥DÃD
- 2
- ºëµØ
- 0
- ¿n¤À
- 15
- ÂI¦W
- 0
- §@·~¨t²Î
- XP
- ³nÅ骩¥»
- XP
- ¾\ŪÅv
- 10
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-11-8
- ³Ì«áµn¿ý
- 2012-12-12
|
±NSQL¬d¸ß¥X¨Óªºµ²ªGÅã¥Ü¦b¬Yºô¶¤W?
½Ð±Ð¥H¤Uµ{¦¡½X(ASP)¸Ó¦p¦óקï¤~·|°õ¦æ¦¨¥\¡A¦]¬°³£¹J¤W¤@¨Ç°õ¦æ¿ù»~¡A§Ú¬O·Q±NSQL¬d¸ß¥X¨Óªºµ²ªGÅã¥Ü¦b¬Yºô¶¤W¡AÁÂÁ¡I
-----------------------------------------------------------------------------------------------------------------------------------------------------
//====== Step 1¡G«Ø¥ß¸ê®Æ®w³sµ²¡AµM«á¶}±Ò¸ê®Æ®w
conn = Server.CreateObject("ADODB.Connection");
conn.ConnectionString = "Driver={SQL Server};Server=XXXX;UID=XX;PWD=XXXX;Database=XXXXXXXX;"
conn.Open();
//====== Step 2¡G°õ¦æSQL«ü¥O¡A¨Ã±N¬d¸ßµ²ªGÀx¦s©ó Recordset ¤¤
sql = "SELECT * from test"; //±q¸ê®Æªí testTable ¨ú¥X©Ò¦³¸ê®Æ
rs = conn.Execute(sql);
%>
<table border=1 align=center>
<tr bgcolor="cyan">
<%
//====== Step 3¡G³z¹L RecordSet ¶°¦X¨ú±oÄæ¦ìªº¤º®e
//¦L¥XÄæ¦ì¦WºÙ
for (i=0; i<rs.Fields.Count; i++)
Response.write("<th>"+rs(i).Name+"</th>\n");
%>
</tr>
<%
//¦L¥X¨C¤@µ§¸ê®Æ
while (!rs.EOF) {
Response.write("<tr>\n");
for (i=0; i<rs.Fields.Count; i++)
Response.write("<td>"+rs(i)+" </td>\n");
rs.MoveNext();
}
%>
</table>
<%
//====== Step 4¡GÃö³¬ RecordSet ¤Î¸ê®Æ®w³sµ²
rs.Close();
conn.Close();
%>
<hr>
---------------------------------------------------------------------------------------------------------------------------------- |
|
¿·
|
|
|
|
|