Syntax for grabbing a variable from a dataset once the correct row is found.

UdiHrant

Member
Joined
Jul 3, 2012
Messages
9
Programming Experience
10+
Yes - Im fairly new to VB.NET and I'm still struiggling with the syntax.

Below you will see code where I succesfully 'find' a row in my table of a dataset. Next I simply want to grab the string value one column (CUR_STUD_DIV).

'This line DOES find the row I want...
foundrow = TmsEPrdDataSet.Tables("Student_Master").Rows.Find(ID_NUM)
' This line produces the error below. AM I doing something wrong with the syntax here?
CUR_STUD_DIV = TmsEPrdDataSet.Tables("Student_Master").Rows(foundrow).Item("CUR_STUD_DIV")
'The error I get is : "Conversion from type 'STUDENT_MASTERRow' to type 'Integer' is not valid."
'Yes I have declared CUR_STUD_DIV as a string.

Thanks for any help here.
 
Also - I would appreciate any book suggestions you may have. So far any books I have picked up are either too advanced or too simple and only cover how to drag controls onto forms! In particular I am a VB6 guy trying to make the jump to .NET.
 
You get the error because 'foundrow' is actually a row, not the index of a row. In this code:
VB.NET:
CUR_STUD_DIV = [B][U]TmsEPrdDataSet.Tables("Student_Master").Rows(found row)[/U][/B].Item("CUR_STUD_DIV")
the highlighted section getting a row by index, but you already have the row and you're trying to use that as an index to find the row that you've already got. If you want to get a field by column name from the row you've found then use the row you've found, not one that you try to get by an index that you don;t have:
VB.NET:
CUR_STUD_DIV = foundrow.Item("CUR_STUD_DIV")
As for books, I've generally found Wrox books to be quite good and they have generally have two levels available on programming languages: Beginning and Professional. You could start with the Beginning book for VB to get a full grounding but it will also teach general programming principles that you may well already be familiar with. Possibly you might use an online tutorial to get through the basic stuff fairly quickly and then go for the Wrox Professional book.

I'd probably suggest that you start here:

Microsoft Visual Basic .NET tutorials for Beginners

Some of it may be a bit simple, especially early on, but it does cover the basics of classes, properties, methods, events, etc, so, if you are already OK with general programming principles, that may well be enough of a grounding VB.NET to make jumping to the Professional book OK. If you feel like much of what's in that online tutorial is new then you might decide to go for the Beginning book first.
 
Thank you SO much! I'm an old school programmer, (Fortran, basic, cobol) so I have a hard time reading this kind of syntax where everything get's kind of hidden inside everythjing else. Didn't realize that I had already built the object I needed when I did the find. Really appreciate your help.

I'll try those books too.
 
Back
Top