Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 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 April 26th, 2004, 12:34 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to get the value from the DataTable column

Hi everybody,
I have a .NET question:
I've created a disconnected OleDb.DataSet. After that I filled in the DataTable for this DataSet using OleDb.DataAdapter. Than, I would like to read some data from some fields in this DataTable. How to get the field value without using DataReader? I am trying to use collections (first table (index 0) in the Tables collection and column (index 11) in the Columns collection:
myVariable = myDataSet.Tables(0).Columns(11).ToString, it returns the column name. How to get the actual value from the column? I could not find any example on the WEB and Microsoft Help.
Any ideas?

Thanks
-Dmitriy.;)
 
Old September 27th, 2006, 11:55 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

just try this

in VB.NET
variable as String=DataSet.Table(0).Rows(index)(column-index).ToString();

in C#.NET

string variable=DataSet.Table[0].Rows[index][column-index].ToString();

Example:

string name=DataSet.Table[0].Rows[3][2].ToString();


hope this help you.

best regards.

 
Old March 27th, 2008, 05:39 PM
Registered User
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get the following error when I try your advice:
Error 1 Cannot apply indexing with [] to an expression of type 'System.Data.DataTable'

 
Old March 31st, 2008, 01:09 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Why would you post your .NET question in the VB6 forum?
 
Old March 30th, 2010, 08:58 AM
Authorized User
 
Join Date: Jan 2010
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elizas
Default Getting the Calculated value for a new column of a DataTable in .NET

DataTable class in .Net supports the calculation of a column by getting the values from other columns.

That means lets say I have a DataTable as dtItems which is having three columns ItemName, Price, Quantity ,if I need to add another column as Total and the calculated value for this column will be Price* Quantity , this can be done easily without looping through all the rows, it will be automatically calculated during runtime " dtItems.Columns.Add("Total", typeof(int), "Price*Quantity"); ".
__________________
Cheers,
Eliza

Mindfire: India's Only Company to be both Apple Premier & Microsoft Gold certified.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rearrange the column order in a datatable/dataset kiran_q8 ASP.NET 2.0 Basics 6 July 3rd, 2007 12:12 PM
Rearrange the column order in a datatable/dataset kiran_q8 ASP.NET 2.0 Professional 2 May 3rd, 2007 08:46 AM
Adding up Column Values within a Datatable rit01 ASP.NET 2.0 Basics 1 May 31st, 2006 11:27 AM
Adding rows, AND column(s) to existing datatable cliffd64 VB.NET 2002/2003 Basics 1 August 18th, 2005 06:50 AM
Compare two Items of data(in column A and column B ever Excel VBA 6 February 13th, 2004 02:19 PM





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