?
Solved

Help convert this aspx page to an exe C# program

Posted on 2007-11-21
4
Medium Priority
?
947 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 600 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 800 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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

741 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