473,569 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve Field Values into Variables

Hi.

I'm new to ASP.Net and I'm running into a simple problem (I think).

I'm trying to get 2 values from 2 separate queries into 2 different
variables. I would then like to take the difference of the two
varaibles and place it into a label on an .aspx page.

Basically,
MyGrossSales = GrossSales from query
MyTotalCredit = TotalCredit from query
MyLabel = MyGrossSales - MyTotalCredit

I can retrieve data and place it into a repeater and/or other data
controls, but I've not found a way to get data into a variable(s) to be
used in code.

Can someone help me with this? Am I on the right track? Is there a
better (or simpler) way to accomplish this?

Here's what I have so far.

----------------- Start of Code ----------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New SqlConnection(" Server=MyServer ;Integrated
Security=True;D atabase=MyDatab ase")
MyCommand = New SqlDataAdapter( "SELECT SUM(tot_dollars ) AS
GrossSales FROM OEORDHDR_SQL WHERE (ord_type = 'I')", MyConnection)
DS = New DataSet
MyCommand.Fill( DS, "GrossSales ")
Repeater1.DataS ource = DS
Repeater1.DataB ind()

Dim DS_2 As DataSet
Dim MyConnection_2 As SqlConnection
Dim MyCommand_2 As SqlDataAdapter
MyConnection_2 = New SqlConnection(" Server=MyServer ;Integrated
Security=True;D atabase=MyDatab ase")
MyCommand_2 = New SqlDataAdapter( "SELECT SUM(tot_dollars ) AS
TotalCredits FROM OEORDHDR_SQL WHERE (ord_type = 'C')", MyConnection_2)
DS_2 = New DataSet
MyCommand_2.Fil l(DS_2, "TotalCredi ts")
Repeater2.DataS ource = DS_2
Repeater2.DataB ind()

End Sub
----------------- End of Code ---------------

I've also read about getting data via something like
DS.Tables.Item( 0).Rows(0)("Gro ssSales"), but I have not figured out how
to use it.

Thank you for your help,
j.t.w

Jul 14 '06 #1
1 1818
Hi JTW,

If understand what you're trying to accomplish, I suspect you can do it all
in one shot within the declarative markup. You can do the math as you
display the result on the table.

Here's an example of what I mean. There are other ways of doing this with a
helper function if this doesn't suit your needs.

Let us know?

Ken
Microsoft MVP [ASP.NET]
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArg s)
Repeater1.DataS ource = CreateDataSourc e()
Repeater1.DataB ind()
End Sub
Function CreateDataSourc e() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add( New Data.DataColumn _
("GrossSales ", GetType(Decimal )))
dt.Columns.Add( New Data.DataColumn _
("TotalCredi t", GetType(Decimal )))
Dim i As Integer
For i = 1 To 5
dr = dt.NewRow()
dr(0) = i + i * 800
dr(1) = i + i * 700
dt.Rows.Add(dr)
Next i
Return dt
End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Field and Variables</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:repeater id="Repeater1" runat="server">
<itemtemplate >
<asp:label id="MyGrossSale s" runat="server" text='<%#
eval("GrossSale s")%>'>
</asp:label><br />
<asp:label id="MyTotalCred it" runat="server" text='<%#
eval("TotalCred it")%>'>
</asp:label><br />
<asp:label id="MyLabel" runat="server" text='<%#
eval("GrossSale s")-eval("TotalCred it")%>'>
</asp:label><br /><hr />
</itemtemplate>
</asp:repeater>

</div>
</form>
</body>
</html>

<j.***@juno.com wrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi.

I'm new to ASP.Net and I'm running into a simple problem (I think).

I'm trying to get 2 values from 2 separate queries into 2 different
variables. I would then like to take the difference of the two
varaibles and place it into a label on an .aspx page.

Basically,
MyGrossSales = GrossSales from query
MyTotalCredit = TotalCredit from query
MyLabel = MyGrossSales - MyTotalCredit

I can retrieve data and place it into a repeater and/or other data
controls, but I've not found a way to get data into a variable(s) to be
used in code.

Can someone help me with this? Am I on the right track? Is there a
better (or simpler) way to accomplish this?

Here's what I have so far.

----------------- Start of Code ----------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New SqlConnection(" Server=MyServer ;Integrated
Security=True;D atabase=MyDatab ase")
MyCommand = New SqlDataAdapter( "SELECT SUM(tot_dollars ) AS
GrossSales FROM OEORDHDR_SQL WHERE (ord_type = 'I')", MyConnection)
DS = New DataSet
MyCommand.Fill( DS, "GrossSales ")
Repeater1.DataS ource = DS
Repeater1.DataB ind()

Dim DS_2 As DataSet
Dim MyConnection_2 As SqlConnection
Dim MyCommand_2 As SqlDataAdapter
MyConnection_2 = New SqlConnection(" Server=MyServer ;Integrated
Security=True;D atabase=MyDatab ase")
MyCommand_2 = New SqlDataAdapter( "SELECT SUM(tot_dollars ) AS
TotalCredits FROM OEORDHDR_SQL WHERE (ord_type = 'C')", MyConnection_2)
DS_2 = New DataSet
MyCommand_2.Fil l(DS_2, "TotalCredi ts")
Repeater2.DataS ource = DS_2
Repeater2.DataB ind()

End Sub
----------------- End of Code ---------------

I've also read about getting data via something like
DS.Tables.Item( 0).Rows(0)("Gro ssSales"), but I have not figured out how
to use it.

Thank you for your help,
j.t.w

Jul 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2050
by: Roar | last post by:
Hi! I have got 1 access 2000 DB, one simple search form, and 3 .asp pages (one for deleting a record, one for inserting a record and one for listing searchresults). Deleting records works fine, Inserting records works fine, but my headache is the searchform.. Whatever i type in the searchbox (sok), the result is all database entries, not...
8
2592
by: Jack | last post by:
Hi, Here is my problem: I am logging in to a page, where the page retrieves a record from a database. The text boxes are used in the display formto let the users update the fields, if they desire to. The colorpreference and foodpreference fields are text fields while the FinalUpdate field is a yes/no field in Access Database.
6
8201
by: Salvani Langosta | last post by:
In an Access 97 database, I use serveral global variables that hold information about the database, for example: gstrFileServer - holds the server root where the database is stored gstrDataServer - holds the server root where a related data warehouse is stored The values of these variables are set when the database is opened. I want to...
8
7083
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: BattID VehicleID STDATE STTIME CTC LKO500HF 00000000 10/27/2003 4:13:51 AM 4 LKO500HF 00000000 10/27/2003 5:13:51 AM 5 LKO500HF 00000000 10/27/2003 10:13:51 AM 6...
9
6810
by: Don | last post by:
Say I have a class like so: Public Class MyClass Public Prop1 as Integer Public Prop2 As Integer Public Prop3 As Integer End Class Is it possible to retrieve a list of the variables or objects declared within an instance of that class if they are declared with Public (or
6
1820
by: zoro | last post by:
Hi, I am looking for the recommended way to retrieve several values from a single record, i.e. a typical lookup scenario. An example would be a query that needs to retrieve user_name, user_addres, user_email for a given user. I know that if I had to get a single values I should use the Command.ExecuteScalar() and that if I need to get...
1
2483
by: glady | last post by:
Hi, I would like to have a php form that gets input from user and display data if they have already entered for that particular record in the same form. For example, if i have a form with 20 fields, if the user already entered 5 (values)field, then it should retrieve 5 values in form as read-only format and remaining 15 fields should be...
5
25541
by: Ken | last post by:
I'm trying to run a loop to capture column property information from a table in my datasource. Can anybody see where this is going wrong? Dim tbl As New DataTable Dim col As DataColumn Dim x As Integer Dim colName(99) As String Dim colType(99) As String cn.Open() tbl = cn.GetSchema("Orders") 'Orders is a table in the
9
4779
by: Mel | last post by:
I have 10 columns total. 3 of them are invisible. The rest are read- only BoundFields, 3 of which are editable fields using TemplateFields. Upon editing, I want to validate what the user enters against one of those invisible columns. How do I accomplish this? The code below that I attempted just returns an empty string when I try to...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.