<%--
   asp code Generated by Basic Processor
   Original Page Name: C:\gmTestBed\FMStocks\src\FMSWeb\ASP\_runsql.asp
--%>

<%@ Page language="C#" explicit="true" CodeBehind="_runsql.aspx.cs" Inherits="FMSWeb.__runsql" %>

<%
   HttpContext.Current.Response.Buffer = true;
%>


<html>
<head>
<% _t_head1.Author_Markup(); %>

	<title>Run SQL Command</title>
</head>
<body>
<% _t_begin1.Author_Markup(); %>

<form method="post" action="_RunSQL.aspx">
<textarea rows="15" cols="40" id="SQLStatement" name="SQLStatement">
<%
   if (!String.IsNullOrEmpty(HttpContext.Current.Request["SQLStatement"]))
   {
      HttpContext.Current.Response.Write(HttpContext.Current.Request["SQLStatement"]);
   }
   else
   {
      HttpContext.Current.Response.Write("select * from stocks where company like '%.com%'");
   }
%>
</textarea>
<input type="submit" value="GO">
<%
   if (!String.IsNullOrEmpty(HttpContext.Current.Request["SQLStatement"]))
   {
      dsn = db.ConnectionString();
      HttpContext.Current.Response.Write("<p>(Using DSN: " + dsn + ")</p>");
      conn.Open(dsn);
      rs = conn.Execute(HttpContext.Current.Request["SQLStatement"]);
      if (rs == null)
      {
         HttpContext.Current.Response.Write("<b>rs is nothing</b><br>");
      }
      else if (((int)rs.State) == 0)
      {
         HttpContext.Current.Response.Write("<b>No results returned</b><br>");
      }
      else
      {
         while (!(rs == null))
         {
            if (((int)rs.State) != 0)
            {
               HttpContext.Current.Response.Write("<table border=1>");
               // header
               HttpContext.Current.Response.Write("<tr>" + "\r\n");
               foreach(gmRTL.DataLib.SqlClient.Field forTemp0 in rs.Fields)
               {
                  f = forTemp0;
                  HttpContext.Current.Response.Write("\t" + "<td><strong>" + f.Name + "</strong></td>");
               }
               HttpContext.Current.Response.Write("</tr>" + "\r\n");
               // data
               while (!(rs.EOF))
               {
                  HttpContext.Current.Response.Write("<tr>" + "\r\n");
                  foreach(gmRTL.DataLib.SqlClient.Field forTemp1 in rs.Fields)
                  {
                     f = forTemp1;
                     HttpContext.Current.Response.Write("\t" + "<td>" + f.Value.ToStr() + "</td>");
                  }
                  HttpContext.Current.Response.Write("</tr>" + "\r\n");
                  rs.MoveNext();
               }
               HttpContext.Current.Response.Write("</table><br>");
            }
            rs = rs.NextRecordset();
         }
      }
   }
%>
</form>
<% _t_end1.Author_Markup(); %>

</body>
</html>
