Record from one table, calcs on each row of another table - what would be the .nettiest way to do this?

Imagine two tables.

Table 1 has various tombstone information, including Latitude and Longitude.

Table 2 has a bunch of locations, each with a latitude and longitude.

I've created a class for various geomaths; in this case, distance between two GPS coords, and bearing from point A to point B.  Set startlat, startlong, endlat, endlong, and read distance and bearing properties, the class does the maths.

 So, what I want to do is read a record from Table 1; this record is displayed, at the moment, in a DetailsView.

I want to read each record from table 2, calculate the distance and bearing to the GPS coordinates from the one record pulled from Table 1, then sort the results, and display each database record with the two calculations - distance and bearing.  Possibly even, say, only the five shortest distances.

What is the proper asp.net / vb.netway to do this?

0
slebrun
8/1/2008 6:54:50 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
633 Views

Similar Articles

[PageSpeed] 52

Hi slebrun,

Based on my understanding, you want to show records in table1 in DetailsView control, meanwhile , retrieve related records in table2 to do some calcs .

So you can write code in DataBound event to do calcs.

 

    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        //code here
    }
  
 <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
              OnDataBound="DetailsView1_DataBound"
            >

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/4/2008 7:09:29 AM

OK, sounds to me like what you're saying is 'in the databound event of the detailsview, where you pull the customer record, you then, say, write some code to pull data from table 2, run your calcs, populate an array, and databind that to a gridview.'  Am I on the right track here?

0
slebrun
8/5/2008 1:36:02 PM

Hi slebrun ,

slebrun:
OK, sounds to me like what you're saying is 'in the databound event of the detailsview, where you pull the customer record, you then, say, write some code to pull data from table 2, run your calcs, populate an array, and databind that to a gridview.'  Am I on the right track here?

Yes , do you want that ?

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/6/2008 4:21:47 AM

I'm just trying to avoid thinking in ASP Classic mode. :-)

A quick rundown on how to access data programatically in ASP.NET, where in ASP you'd:

set rsRecordSet = dbMyDatabase.Execute(strSqlStatement)
fGpsLatitude = rsRecordSet("GpsLat")
fGpsLongitude = rsRecordSet("GpsLong")

Set rsRecordSet2 = dbMyDatabase.Execute(strOtherSqlStatement)

Do while Not rsResultSet2.EOF
fNewLat = rsResultSet2("GpsLat")
fNewLong = rsResultSet2("GpsLong")
fDistanceInKM = CalculateDistance(fGpsLatitude, fGpsLongitude, fNewLat,fNewLong)
Response.Write fDistanceInKM & " KM distant.<br>"


rsResultSet2.MoveNext
Loop

 

would be nice. :-)  Or at least, some pointers on what I should be looking up in Help.  I'm still new to vb.net and asp.net, but figured, hey, need to quit using ASP classic sometime...

0
slebrun
8/7/2008 7:18:50 PM
Reply:

Similar Artilces:

can I compare one record from one table to another record in another table?
can I compare one record from one table to another record in another table? I need to test if this condition is met. My scenario is: i need to check one table for a value and compare it to a list of records. for example, table 1           columnrecord 1- applesrecord 2- orangesrecord 3- grapes table 2            col1   col2   col3    col4record 1- Null , Null, Null, grapes I need to compare table 2 records with a list of records from table 1. the fru...

1 record from one table N records from another table using gridview in single row?
Hi there, I have 2 tables named question(questionid,question) and options(optionid,options) In that questions table I got one record and in options table 3 records. Whenever I query I got 3 records 1)question1 choice1 2)question1 choice2 3)question1 choice3 I would like to use gridview(I would like to edit those values) to display these in a single row. like Question1 ch1 ch2 ch3(one record) . But the problem is I always getting 3 rows. I have seen some example(nested datalist) but they are using only one table, I am using 2 tables. Can any one help me to acheive th...

how to order records from one table by records of another table?
i have two tables: subject ~~~~~~~ name number (primary key document ~~~~~~~~ name, number (primary key) subject_number (foreign key) what SQL query will return a table (view) of the subjects, ordered by the number of documents each subject has? subjects with no documents should not be included. Hello, Following is a query: SELECT subject.name, Document.name FROM subject INNER JOIN Document1 ON subject.number = Document.subject_number ORDER BY Document.name Dear, this is not a SQL centric blog. So its may not possible every time to solve SQL relat...

Deleting rows from one table based upon rows in another table
I need to delete rows from table1 based on rows in table2. table1 has 1.5 million rows from which I need to delete 20,000 existing in table2. The table structures are the same and I must exactly match 10 (of the 15) columns in the tables. I also need to limit the number of rows being worked on, in a single transaction, to 500 or so. Hi Mike, try the following: set rowcount 500 DELETE table1 from table1 t1,table2 t2 where t1.col1=t2.col1 and t1.col2=t2.col2 and t1.col3=t2.col3 and ........ t1.col10=t2.col10 HTH. Regards P:S You must re-execute the DML statement above 40 time...

How to change the Rows of the one table to another table
I want's to change the layout of my table at run time on the basis of some of my Setting File[I don't want's to use webpart orwebzones]Suppose I have three Tables with number of rows.[In reality Each row will contain some controls]On Page_Preinit I want's to set the rows of one table to another also want's to change order of the rows.How Can I do that ?  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/...

Insert multiple records from one table to another table
Hello. Got a quick problem. I need to post shopping cart items from a temperary table "ShopCart" to a permanent table "tbl_orders". Problem is, I cannot figure out how to iterate through the recordset to post the unique products from "ShopCart" to "tbl_orders". The code below inserts the first product-- but that's it. If there are 6 different products, it will insert the first product 6 times. Public Sub GetShopCart() Dim ordernumber = session("ordernumber") Dim objConn as new SqlConnection(strConn) Dim strSQL as Str...

Copying html table rows from one table to another.
Hi Im am trying to copy table rows from one html table to another. Below is a one of my many attempts and all this does is moving the rows from the one table to the other. I would appreciate any help. int iCount; HtmlTableRow[] TableRows = new HtmlTableRow[Table1.Rows.Count]; Table1.Rows.CopyTo(trs,0); for (iCount = 0; iCount < TableRows.Length; iCount++) { Table2.Rows.Add(TableRows[iCount]); } Thanks ...

Copy Records From one table to another table with same structure
Hi allI have two tables in SqlServer with Exactly Same Structure,I want to Copy all Records fromone of them to another one.I came across to "Insert....select..." statement But i have two problem 1) I don't know any thing about Columns name!!! i just know they have same structure and as far as i know , "Insert...select..." need the Column list to operate correctly, am i right? 2) these two table have One Prinary Key column with IDENTITY feature. Any Help Greatly appriciated.Regards.Nothing Is Quite Impossible !!! Personally, i found DTS is the best way you just need to set&nbs...

Update a rows in one table for each row in other table
Hello all, i am a newbie in SQL and i want to ask for your help in order to do the following update statement. I have a table tblUsers which holds all the users, one of the fields in their GroupId. In the UserGroup table i have a field "UsersCount" and in that field i want to keep the number of the users in that group. Basically i want everytime i am saving a user to recalculate the users in all usergroups. I am trying to have something like:SELECT User_GroupId, count(User_GroupId) as UsersCount FROM tblUsersWHERE DeletedFlag = 0 GROUP BY User_GroupId and then:"FOR EACH" User_GroupIdUPDAT...

Updating records in one table relating to data in another table
I have two tables "websites" and "oldlistings" , whereas websites has a field named "linkname", and oldlistings has a field named "company" that will both be the same exact data for each record (no relationship has been formed): CREATE TABLE [dbo].[websites](    [webid] [int] IDENTITY(1,1) NOT NULL,  ...    [linkname] [varchar](80) NULL,... CREATE TABLE [dbo].[oldlistings](     [oldid] [int] IDENTITY(1,1) NOT NULL,   ...     [company] [varchar](80) NULL,... I need t...

Need to transfer certain rows from one table into another table
On my online store, I need to figure out with sql how I can copy data from several different tables into another table: There is a table that contains all of the customers billing infoanother table has customer's shipping info The target table is for tracking and processing orders.  I will need to populate different fields from different tables, as well as insert values into fields from my code behind (i.e. customers can choose different types of shipping, payment options).  I googled this and keep running into the join statement (which I use all the time).  I don't ...

Copy rows from one table control to another
Hi AllI want to copy the rows from one ASP.net Table control to another but I'm having problems. I'm getting the following error:"Collection was modified; enumeration operation may not execute. "However I'm sure I'm not modifying the collection as I copy each row.The code is pretty simple. The QuoteMatrix.CreateCoverMatrix() method just returns a table to the caller and then I create a new table based on the rows in the retuned table: Dim table1 As New Table() Dim table2 As New Table() table1 = QuoteMatrix.CreateCoverMatrix() For...

More Tables OR all the records in one Table?
Hello Let's say that a company has about 20 000 (20 Thousand) users with each capable of storing specific info of up to around 500 records thus a total of about 10 000 000 (10 million) records. And each user will pull all of his/her own records (up to about 500) everytime he/she starts the app on his/her machine. Would you create multiple tables and spread the users across those tables thus keeping each user's records in one table, but a few users per table... OR will you keep all users' records in only one table? Thanks PeaShooter_OMO > Let's say that a...

Getting information from one table and applying it to another table record.G
Hello, I'm creating a website in ASP.NET and C#, My problem is I want to add a new record to a table using data from another table. i.e. Add a book, to set the book category you have to select if from a databound dropdown in another table. All those categories are stored in a different table. I'm not sure how to do that. Any help is appreciated. Thanks a lot!! Gabriel do datasource copy in the server-side or javascript copy in the client-sideRichard Tsuei (Chikun Cui)Contact me via E-mail: ricktsuei@gmail.comWeblog: http://ricktsuei.cnblogs.com+-+-+-+-+-+-+-+-+-+-+-+-+-...

Web resources about - Record from one table, calcs on each row of another table - what would be the .nettiest way to do this? - asp.net.presentation-controls

Resources last updated: 11/25/2015 6:49:26 PM