Solved

Help convert this aspx page to an exe C# program

Posted on 2007-11-21
4
937 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting PHP triple des decrypt to c# 9 162
C# LINQ 5 41
Adjust the codes 3 63
input validations, TryUpdateModel and model binding  in asp.net mvc 5 21
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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