<% ' ■■■■■■■■ Sample for Web Application ■■■■■■■■ '============ form からの受け渡し変数を取得します username = Request.Form("username") '============ データベースへのコネクションを定義します set Connection = Server.CreateObject("ADODB.Connection") '============ 「aspDSN」という ODBC データソースを使って, '============ コネクションを開きます Connection.open "aspDSN","sa","" '============ 新規社員をデータベースに追加します '============ Execute は,指定された SQL 文を実行するために使います if username <> "" then Connection.Execute("insert TEST(名前) values('" & username & "')") end if '============ 読み取り用 SQL 文を定義します. '============ これは,普通の文字列変数です. sql_select = "select ID,名前 from TEST" '============ 実際に SQL 文を発行して,結果を RS_select に取得します '============ このように,文字列変数を使って SQL 文を発行することも '============ できます. set RS_select = Connection.Execute(sql_select) %> 社員リストを取得する

社員リスト


<% '============ RS_select の内容を表示する '============ RS_select が終了(eof)するまで,ループしながら値を取り出す while not RS_select.eof %> <% '============ ループの終わり.RS_select を次の行に進めて, '============ ループの初めに戻る RS_select.MoveNext wend %>
<%=RS_select("ID")%> <%=RS_select("名前")%>
**
<% '============ 後処理.RS_select を閉じて,Connection も切断 RS_select.Close Connection.Close %>