I have an aspx page that does sql operations against a database. The database has been growing and now the page takes too long to load. I want to convert it into an exe program so I can run it on the scheduler. I'm so used to ASP.NET and needed help with putting it into plain C#. Here's what I got:
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configur
ation" %>
<%@ Import Namespace="System.Collecti
ons" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Conf
iguration"
%>
<%@ Import Namespace="System.Web.Secu
rity" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.W
ebControls
" %>
<%@ Import Namespace="System.Web.UI.W
ebControls
.WebParts"
%>
<%@ Import Namespace="System.Web.UI.H
tmlControl
s" %>
<%@ Import Namespace="System.Data.Odb
c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" >
public void Page_Load(object sender, EventArgs e)
{
string connString = "Dsn=" + Request.QueryString["id"];
OdbcConnection conn = new OdbcConnection(connString)
;
//Select Order Sums of QtyOrdered and QtyToShip
DataSet dsOrders = new DataSet();
OdbcDataAdapter adapter = new OdbcDataAdapter(null, conn);
adapter.SelectCommand.Comm
andText = "SELECT * FROM orders";
adapter.Fill(dsOrders, "OrderCalc");
//Update database with new ship percentage field
OdbcCommand UpdateCommand = new OdbcCommand();
UpdateCommand.Connection = conn;
string updateSql;
decimal shipPct;
foreach (DataRow row in dsOrders.Tables["OrderCalc
"].Rows)
{
if (Convert.ToDecimal(row["Qt
yToShip"])
== 0)
shipPct = 0;
else
shipPct = Decimal.Round((Convert.ToD
ecimal(row
["QtyToShi
p"]) / Convert.ToDecimal(row["Qty
Ordered"])
* 100), 1);
updateSql = "UPDATE shiptable SET ShipPct=" + shipPct + ", Fld_12='Y' WHERE XA=" + row["XA"] + " AND XB=" + row["XB"];
UpdateCommand.CommandText = updateSql;
try
{
conn.Open();
UpdateCommand.ExecuteNonQu
ery();
}
catch { }
finally
{
conn.Close();
}
}
LiteralStatus.Text = "Loading...";
}
</script>
<html xmlns="
http://www.w3.org/1999/xhtml"
>
<head runat="server">
<title>Process Order Ship Dates</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<b><asp:Literal ID="LiteralStatus" runat="server"></asp:Liter
al></b>
</div>
</form>
</body>
</html>
Start Free Trial