[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Help convert this aspx page to an exe C# program

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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