Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 27th, 2007, 09:14 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old June 27th, 2007, 10:38 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old June 27th, 2007, 11:56 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
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.
Reply With Quote
  #4 (permalink)  
Old June 28th, 2007, 05:19 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #5 (permalink)  
Old July 2nd, 2007, 10:19 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.