Solved

Help convert this aspx page to an exe C# program

Posted on 2007-11-21
4
932 Views
Last Modified: 2013-12-16
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.Configuration" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Data.Odbc" %>

<!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.CommandText = "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["QtyToShip"]) == 0)
            shipPct = 0;
        else
            shipPct = Decimal.Round((Convert.ToDecimal(row["QtyToShip"]) / Convert.ToDecimal(row["QtyOrdered"]) * 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.ExecuteNonQuery();
        }
        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:Literal></b>
    </div>
    </form>
</body>
</html>
0
Comment
Question by:bemara57
  • 2
4 Comments
 
LVL 1

Assisted Solution

by:MCKreed
MCKreed earned 150 total points
ID: 20331711
It looks you are using data from one table to update data from another. You are using a query string to point to a server.

If you want to do this in a simple exe there is not a lot of work to do.

You'll want some sort of input to point to a server  like a text box. Where you request the Query string, you could use textbox1.text.

The form will have a form load event where you can put the code you already have.

You won't have to make all those imports but some you will have to like system.data and system.data.odb. After you create an new app in VS Open the code for the form and at the top include using system.data; or what ever you need to import.

0
 
LVL 2

Accepted Solution

by:
koolnurd earned 200 total points
ID: 20333728
create a console app in C#.
use below libraries only...And put all form load code in the main of that app.

THats it you are done....create exe of it and use..

using System;
using System.Data;
using System.Configuration;
using System.Collections;
0
 
LVL 2

Expert Comment

by:koolnurd
ID: 20333731
sorry Not a console app .....
you want text also
Go for window app.... and copy your page load to Form load....

rest same as above....
0
 
LVL 3

Assisted Solution

by:Aurora27
Aurora27 earned 150 total points
ID: 20336754
Get the connection string set, import all the required lib and then put this in a function:

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.CommandText = "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["QtyToShip"]) == 0)
            shipPct = 0;
        else
            shipPct = Decimal.Round((Convert.ToDecimal(row["QtyToShip"]) / Convert.ToDecimal(row["QtyOrdered"]) * 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.ExecuteNonQuery();
        }
        catch { }
        finally
        {
            conn.Close();
        }
    }


Call this fn . from Main () or Form Load() and then add labels for showing status...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now