Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
VB
var = ds.Tables(0).Rows(0)(12)

i m getting error in the above line..the application getting closed automatically..i am trying to fetch the 12th column of the table and save it in the variable 'var'
Posted
Updated 4-Oct-12 3:38am
v3
Comments
Venkatesh Mookkan 4-Oct-12 8:55am    
I have updated the answer!
fjdiewornncalwe 4-Oct-12 9:20am    
As a comment, you should avoid using a variable name like "var" because it simply isn't descriptive of what you are getting back. If you make a habit of naming your variables in a very generic way your code will quickly become unreadable. In development, clarity is of the utmost importance. Cheers.

To fetch the value of 12th column, you should use 11 as the index always starts from 0.

The only possible reason that the application is crashing could be, you are accessing column which does not exists.
 
Share this answer
 
v2
Comments
Joan M 4-Oct-12 3:06am    
What I find amusing is that the compiler has not imploded after reading that...
Can it be used for anything?
Kenneth Haugland 4-Oct-12 9:39am    
This might be my fault, I tageed the code C#, it should have been VB. Var is not a designated method or expression in VB, but it is in C#...
Venkatesh Mookkan 4-Oct-12 8:53am    
Hey Joan. I checked in VB.NET, its allowing var as variable name. Its seems like the index issue.
Put the Proper Try Catch block to see the actual error.
put the section of code into the Try catch for catching the exception and preventing application to close directly.

The column/row index is always start from the 0 in the DataSet table
 
Share this answer
 
v2
Hi,
Try this one for retrieving 12th column value

Dim d = ds.Tables(0).Rows(0).Item(11)

(or)

Dim d As String = ds.Tables(0).Rows(0)(11)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900