Excecute Query in ASP.net using one page

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
Hi there...

How would I go about for using 2 textboxes in an ASP.net to be used in the SQL statement to display data in the GridView...?

Below is the code of my page:

Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>XCSA | Latest Updates</title>

<link href="../../../../../assets/css/xcsa_master.css" rel="stylesheet" type="text/css" />
</head> 

<body>           
    <form id="form1" runat="server">   
<div id="siteHeader"></div>  
<div id="DivWrapper">
  <div id="Date"><a href="../../../../../default.aspx" class="availableLink">home</a>   
      » <span class="deadLink"> <a href="../../default.aspx" class="availableLink">3g 
      administration</a></span><span class="inheritLink"> »</span><span class="deadLink"> 
      per complex for month</span></div>
  <div>
    <h1>Per Complex / For Month</h1></div>
  <div class="randomQuotes">Below you will find a liBelow you will find a list of all 
      the dated development processes of the XCSA Intranet.</div> 
      [COLOR="MediumTurquoise"]<div class="content01">Enter 'Year':&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
          <br />
          Enter 'Month':&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;           <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp; 
          <br />
          <br />
          <asp:Button ID="Button1" runat="server" Text="Execute" />
        </div>[/COLOR]  <div class="content02" id="content03">
        [COLOR="YellowGreen"]<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/assets/database/3GAdmin.mdb" 
            SelectCommand="SELECT MainInfo.Location, SUM(Billing.TotalExVAT) AS SumOfTotalExVAT FROM (MainInfo INNER JOIN Billing ON MainInfo.ID = Billing.LINK) GROUP BY MainInfo.Location, Billing.BillingDate">[/COLOR]</asp:AccessDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" CellPadding="4" DataSourceID="AccessDataSource1" 
            ForeColor="#333333" GridLines="None">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="Location" HeaderText="Complex:" 
                    SortExpression="Location" />
                <asp:BoundField DataField="SumOfTotalExVAT" HeaderText="Total (Excl VAT - R):" 
                    SortExpression="SumOfTotalExVAT" />
            </Columns>
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        </div>
  <div id="Copyright"> 
  Copyright © Xstrata Coal South Africa. All rights reserved | User IP address: %
Dim ipAddress As String
    ipAddress = System.Web.HttpContext.Current.Request.UserHostName 
response.write(ipAddress)
%> 
  	    | <a href="webmaster.aspx" class="copyrightLink">Webmaster</a></div> <!--Code for Copyright Notice ends here-->
</div> <!--Code for Copyright Notice ends here-->
</div>

    </form>

</body>
</html>

The CODE marked in medium terquoise is the code for the textboxes and the submit button, and the code marked in green is the SQL statement.

My question now is - when a user clicks on the submit button, it should post the data filled into the textboxes into the SQL query to be executeded then... Any suggestions how I would do that...?
 
Code:
SELECT MainInfo.Location, SUM(Billing.TotalExVAT) AS SumOfTotalExVAT FROM (MainInfo INNER JOIN Billing ON MainInfo.ID = Billing.LINK) GROUP BY MainInfo.Location, Billing.BillingDate
HAVING (((Billing.BillingDate) Like [COLOR="Red"][B]TextBox1[/B][/COLOR] & "/" & [COLOR="red"][B]TextBox2[/B][/COLOR] & "/" & "*"));

This is what the SQL should look like (or something similiar), where the TextBoxes' info will be used in this query... But it must display the GridView and post the data in the form elements AFTER I have clicked the "Execute" button...
 
Request Object in ASP.NET ;) Request.Form( "TextBox1" )

Um, and lose the ../../../../../../.. parent path linkage please. Trust me on that
 
What he said. Oh, and please, use parameterised queries. Never in-line queries...
 
Top
Sign up to the MyBroadband newsletter
X