Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2007, 09:14 PM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datatables - referencing the data in VB Code

 I have searched numerous places, and can find no lead on this.

Let us assume I have a DataSet named "Students" and a Datatable within this called "Results"

The Columns I have are Year, John, Grant, George, ie. for each year John, Grant and George will have a result, as set out below, with Year as the primary key?

Year John Grant George
1992 78 74 61
1991 91 82 63
1990 85 67 69

My question is, how do I then reference a particular cell to use my VB Code, say John's score in 1991 (which is 91) as a Variable say called Final Score?

i.e. FinalScore = John's Score in 1991
JP.



JP.
 
Old June 27th, 2007, 10:38 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If it is always known you can do

Dim finalScore as Integer = Convert.ToInt32(dt.Rows(1).Item("John").ToString() )

otherwise you can do something like
Dim filter as String = "Year = 1991"
Dim d[] as DataRow = DataTable.Select(filter)
Dim finalScore = Convert.ToInt32(d[0].Item("John").ToString())

hth


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old June 27th, 2007, 11:56 PM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey there,

Thanks for your response. Yes, the datatable will always be known,... so that its fine.

For the 2nd solution you gave, using the DataSet name "Students" & Datatable name "Results" am I correct in thinking that I would need to specify something like

Dim datatable as Datatable = Students.Tables("results")

earlier to ensure I am using the correct datatable?

Also, in the 1st solution what does the 1 in dt.Rows(1) represent? Is this referring to Row 1.

Cheers again. This is starting to make a lot more sense!

JP.

JP.
 
Old June 28th, 2007, 05:19 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes you will need to do Students.Tables("results") to get the correct datatable.

dt.Rows(1) returns the SECOND row from the table (Rows() is a 0 based collection).

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old July 2nd, 2007, 10:19 PM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help!

It was just the lead in I needed, and have got it going great now.



JP.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Referencing Data in Subforms avsrule Access 3 December 13th, 2008 07:34 PM
Referencing data on external drive startfarm ASP.NET 2.0 Basics 4 June 9th, 2008 06:20 PM
How to? Crystal report - vb.net - datatables aboredman Crystal Reports 0 November 13th, 2007 03:54 PM
Referencing a "div" tag in a code behind file. cjo ASP.NET 1.0 and 1.1 Basics 2 December 23rd, 2003 01:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.