Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi all
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 3-Oct-12 20:04pm
Edited 4-Oct-12 3:38am
v3
Comments
Venkatesh Mookkan at 4-Oct-12 8:55am
   
I have updated the answer!
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
Joan Murt at 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 at 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 at 4-Oct-12 8:53am
   
Hey Joan. I checked in VB.NET, its allowing var as variable name. Its seems like the index issue.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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)
  Permalink  
v3

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

  Print Answers RSS
0 Nirav Prabtani 304
1 OriginalGriff 237
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100