Is VB 2005 different from VB 2002 and 2003?

Greasy

Member
Joined
Aug 19, 2006
Messages
8
Programming Experience
Beginner
I am learning VB.Net and have been following the code in Beginning VB.Net 2nd edition from Wrox press. I have a copy of vs 2005 and am getting errors when trying to test the Sql data base stuff in chapter 15 and 16.

When i place the code as they state in the the code examples i get errors such as the SqlConnection is not defined. It will go away when i actuall place the code for that Sqlconnection inside the form load area, but then i have other issues with the DataAdapter code.

I am lost now and could use some help please. Its really anoying when a book that should be teaching you is incorrect in the way the code is written.
 
The ADO.NET code is "for the most part" backward compatible with prior versions, unless you want to use new features in 2005. Post your code and we'll gladly take a look and help you sort out the errors you are receiving.
 
I have wiggled the code all around and finally got it to work. my little nubblet self figured it out. lol.

Their code was
Dim myConnection As SqlConnection = New SqlConnection("Data Source=whatever;Initial Catalog=pubs;Persist Security Info=True;User ID=blah;Password=whatever")
Dim myAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT authors.au_id, au_lname, au_fname, " & "titles.title_id, title, price " & "FROM authors " & "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & "JOIN titles ON titleauthor.title_id = titles.title_id " & "ORDER BY au_lname, au_fname", myConnection)


My code is
Dim myConnection As New SqlConnection("Data Source=blahbla;Initial Catalog=pubs;Persist Security Info=True;User ID=me;Password=password")
Dim myAdapter As New SqlDataAdapter("SELECT authors.au_id, au_lname, au_fname, " & "titles.title_id, title, price " & "FROM authors " & "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & "JOIN titles ON titleauthor.title_id = titles.title_id " & "ORDER BY au_lname, au_fname", myConnection)
 
The two code listings you posted are synonymous in both VB2003 and VB2005. THere isnt any reason i can see why one would work and the other not. It is possible that you have not added a Reference to System.Data and System.Data.SqlClient. On the Project menu, click Add Reference..


Once you have added the reference, it means VB has become aware of the extra code. You still have to write:

Dim x as System.Data.DataAdapter


To cut down on the typing, you write:
Imports System.Data

at the top of the code, outside of the namespace and class declarations


note, if you do not add a reference, then System.Data will not exist. This is the difference between adding a reference and importing the namespace
 
Incidentally.. with respect to data access, VS2003 and VS2005 are sufficiently different that you would be better getting a book on VS2005 or at least doing a google for "Data Walkthroughs" and reading the results from MSDN (microsoft)
 
Thank you. Also where can i find reference material that shows me a breakdown of what all the actual VB code does. Such as System.Data etc. My lingo isnt up to par yet so bear with me. Are there any books that are nothing but Refference material that show each item inside these and what they do?
 
Yeah, i found what i needed there, thanks.

What is the best way to learn VB, and what are the best books to get?
 
System.Data is a namespace; a way of organising a collection of classes all related to Data access and database work.

Inside of this namespace there are specific namespaces for sub packages like System.Data.OracleClient and System.Data.SqlClient

Each namespace is targeted at a different grouping of classes, but the overall use of them remains consistent as possible for the differences in the SQLServer and Oracle databases


Think of namepsaces as analogous to Folders on a hard drive. The files inside are the classes within the namespace. Folders are intended for grouping related files.

One of the best ways to learn is ask someone who knows more than you. If you choose this route, please ask specific questions as broad ones on online forums tend to go ignored because of the effort required to answer - The longer you spend asking a question, the more a potential answerer will be wiling to devote his free time to answering.
 
incidentally, if you want to walk the namespace tree, press F2 in VB and just have a look at the hierarchy. Sometimes I just read the names and wonder about them. Later if I need to do specific things, i think about the names i remember and see if any are likely candidates. F2 has a search too
 
Back
Top