Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > BOOK: Beginning VB.NET Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET Databases
This is the forum to discuss the Wrox book Beginning VB.NET Databases by Thearon Willis; ISBN: 9780764568008
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 15th, 2005, 02:35 AM
Registered User
 
Join Date: Mar 2005
Location: Brisbane, Queensland, Australia.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default WROX's Beginning VB.Net Databases by Thearon

On page 104, of WROX's Beginning VB.Net Databases by Thearon Willis ISBN: 0-7645-6800-0, they have the code:

    Private Sub btnDataReader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataReader.Click
        'Validate connection state
        If Not IsConnectionOpen() Then
            Exit Sub
        End If

        'Declare and initialize a new instance of the OleDbCommand class
        Dim objCommand As New OleDbCommand(txtSQL.Text, objConnection)

        'Set the CommandType property
        If optText.Checked Then
            objCommand.CommandType = CommandType.Text
        Else
            objCommand.CommandType = CommandType.TableDirect
        End If

        'Declare a OleDbDataReader object
        Dim objDataReader As OleDbDataReader

        'Declare a String variable
        Dim strData As String

        Try
            'Execute the SQL text
            objDataReader = objCommand.ExecuteReader()

            'Check to see if we have data
            If objDataReader.HasRows Then
                'Process all rows
                While objDataReader.Read()
                    'Clear the variable
                    strData = String.Empty
                    'Get the data in each column
                    For intIndex As Integer = 0 To objDataReader.FieldCount - 1
                        strData &= objDataReader.Item(intIndex).ToString & ", "
                    Next
                    'Remove the last comma from the string
                    strData = strData.Remove(strData.Length - 2, 2)
                    'Write the data to the TextBox
                    txtSQL.Text &= ControlChars.CrLf & strData
                End While
            End If

            'Close the reader
            objDataReader.Close()
        Catch OleDbExceptionErr As OleDbException
            MessageBox.Show(OleDbExceptionErr.Message, "Access SQL")
        End Try

        'Cleanup
        objCommand.Dispose()
        objCommand = Nothing
        objDataReader = Nothing
    End Sub

    Private Sub btnDataAdapter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataAdapter.Click
        'Validate connection state
        If Not IsConnectionOpen() Then
            Exit Sub
        End If

        'Declare and initialize a new instance of the OleDbCommand class
        Dim objCommand As New OleDbCommand(txtSQL.Text, objConnection)

        'Set the CommandType property
        If optText.Checked Then
            objCommand.CommandType = CommandType.Text
        Else
            objCommand.CommandType = CommandType.TableDirect
        End If

        'Declare a OleDbDataAdapter object
        Dim objDataAdapter As New OleDbDataAdapter

        'Declare a DataSet object
        Dim objDataSet As New DataSet

        'Set the SelectCommand for the OleDbDataAdapter
        objDataAdapter.SelectCommand = objCommand

        Try
            'Populate the DataSet
            objDataAdapter.Fill(objDataSet)

            ''Bind the DataSet to the DataGrid
            'grdResults.DataSource = objDataSet
            ''Tell the DataGrid which table in the DataSet to use
            'grdResults.DataMember = objDataSet.Tables(0).TableName

            'Alternate data binding
            grdResults.SetDataBinding(objDataSet, objDataSet.Tables(0).TableName)

            'Set the AlternatingBackColor property
            grdResults.AlternatingBackColor = Color.WhiteSmoke

            'Set the GridLineStyle property
            grdResults.GridLineStyle = DataGridLineStyle.None

            'Set the SelectionBackColor and SelectionForeColor properties
            grdResults.SelectionBackColor = Color.LightGray
            grdResults.SelectionForeColor = Color.Black

        Catch OleDbExceptionErr As OleDbException
            MessageBox.Show(OleDbExceptionErr.Message, "Access SQL")
        End Try

        'Cleanup
        objCommand.Dispose()
        objCommand = Nothing
        objDataAdapter.Dispose()
        objDataAdapter = Nothing
        objDataSet.Dispose()
        objDataSet = Nothing
    End Sub

When I try to compile this code I receive the following errors:

           Code snippet

            'Execute the SQL text

            objDataReader = objCommand.ExecuteReader()



            'Check to see if we have data

                        If objDataReader.HasRows Then


Error Message

            “HasRows is not a member of ‘SystemData.OLEDB – Line 344





I also received the following error

      Code Snippet

For intIndex = 0 To objDataReader.FieldCount - 1

                        strData &= objDataReader.Item(intIndex).ToString & ", "

            Next



Error Message

            Name IntIndex is not declared – line 350



Can you please provide me with a solution to the above problems as I am keen to continue the exercises?



Regards

Peter Renwick

Brisbane, Queensland, Australia


Peter
Reply With Quote
  #2 (permalink)  
Old March 15th, 2005, 07:15 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Peter,

This sounds as if you are using Visual Studio 2002. The HasRows property was introduced in Visual Studio 2003 with version 1.1 of the .Net Framework.

Can you verify the version of Visual Studio that you are running and then let's see if we can't provide a work around for you.

Thearon
Reply With Quote
  #3 (permalink)  
Old March 16th, 2005, 03:27 AM
Registered User
 
Join Date: Mar 2005
Location: Brisbane, Queensland, Australia.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for the quick response. Yes you are correct I am using Visual Studio 2002.

Do you have a fix please?

WIll this continue to be a problem as I work through the book?

Many thanks
Peter

Peter
Reply With Quote
  #4 (permalink)  
Old March 16th, 2005, 06:39 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Peter,

This simplest solution for you is to comment out the line of code that contains this IF statement:

If objDataReader.HasRows Then

Don't forget the also comment out the corrseponding End If statement.

As far as your other error goes the line should have been coded as:

For intIndex As Integer = 0 To objDataReader.FieldCount - 1

The intIndex variable is declared inline as part of the For statement.

Thearon
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net 2008 re: VB.NET databases book bigbearjeff VB.NET 0 June 2nd, 2008 01:22 PM
ISBN: 0-7645-6800-0 :Beginning VB.NET Databases Aiking BOOK: Beginning VB.NET Databases 1 July 11th, 2006 09:37 AM
Beginning ASP.Net Databases Using VB.Net ISBN 6195 tlamazares SQL Server ASP 1 December 15th, 2003 01:28 PM



All times are GMT -4. The time now is 06:56 PM.


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