Solved

Help convert this aspx page to an exe C# program

Posted on 2007-11-21
4
935 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 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