Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2004, 04:42 PM
jem jem is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by solva
 How does the code on page638 of 'Beginning VB.Net 2nd edition' need to be adapted for use with OLE.

I keep getting an error message at
Code:
myDataAdapter.Fill(myDataSet, "customers")
this si the error message

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll




here is my whole code I adapted for my use with an Access database called concord.



Code:
' IMport Data and Oledb namespaces
Imports System.Data
Imports System.Data.OleDb

Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim myConnection As OleDbConnection = New _
        OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source = c:\concord.mdb")
    Dim myDataAdapter As New OleDbDataAdapter()
    Dim myDataSet As DataSet = New DataSet()

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Set the SelectCommand properties
        myDataAdapter.SelectCommand = New OleDbCommand()
        myDataAdapter.SelectCommand.Connection = myConnection
        myDataAdapter.SelectCommand.CommandText = _
            "SELECT CustNum, WorkPhone, Alt Phone, Firstname, LastName, Address, Address1, City, StateOrProvince " & _
            "FROM customer " & _
            "ORDER BY LastName, LastName"
        myDataAdapter.SelectCommand.CommandType = CommandType.Text

        ' OPen the database connection
        myConnection.Open()
        'Now execute the command
        myDataAdapter.SelectCommand.ExecuteNonQuery()
        ' Fill DataSet object with data
        myDataAdapter.Fill(myDataSet, "customers")

        'Close the database connection
        myConnection.Close()
        ' Set the dataGrid properties to bind it to our data
        grdCustomerInfo.DataSource = myDataSet
        grdCustomerInfo.DataMember = "customers"
    End Sub
End Class
"I'm Still Learning" Neely Fuller Jr.
 
Old February 1st, 2004, 04:44 PM
jem jem is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by solva
 How does the code on page638 of 'Beginning VB.Net 2nd edition' need to be adapted for use with OLE.

I keep getting an error message at
Code:
myDataAdapter.Fill(myDataSet, "customers")
this si the error message

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll




here is my whole code I adapted for my use with an Access database called concord.



Code:
' IMport Data and Oledb namespaces
Imports System.Data
Imports System.Data.OleDb

Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim myConnection As OleDbConnection = New _
        OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source = c:\concord.mdb")
    Dim myDataAdapter As New OleDbDataAdapter()
    Dim myDataSet As DataSet = New DataSet()

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Set the SelectCommand properties
        myDataAdapter.SelectCommand = New OleDbCommand()
        myDataAdapter.SelectCommand.Connection = myConnection
        myDataAdapter.SelectCommand.CommandText = _
            "SELECT CustNum, WorkPhone, Alt Phone, Firstname, LastName, Address, Address1, City, StateOrProvince " & _
            "FROM customer " & _
            "ORDER BY LastName, LastName"
        myDataAdapter.SelectCommand.CommandType = CommandType.Text

        ' OPen the database connection
        myConnection.Open()
        'Now execute the command
        myDataAdapter.SelectCommand.ExecuteNonQuery()
        ' Fill DataSet object with data
        myDataAdapter.Fill(myDataSet, "customers")

        'Close the database connection
        myConnection.Close()
        ' Set the dataGrid properties to bind it to our data
        grdCustomerInfo.DataSource = myDataSet
        grdCustomerInfo.DataMember = "customers"
    End Sub
End Class
"I'm Still Learning" Neely Fuller Jr.
]"ORDER BY LastName, LastName"
Should be "Order by LastName, FirstName"






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16 Fig 16-11 krsouthern BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 1 July 8th, 2008 12:11 PM
Chapter 16 yspider BOOK Beginning CSS: Cascading Style Sheets for Web Design, 2nd Ed; ISBN: 978-0-470-09697-0 1 June 19th, 2008 10:27 AM
Chapter 16 boyce0324 VB.NET 2002/2003 Basics 1 June 5th, 2007 01:59 AM
Chapter 16 czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 3 April 11th, 2005 11:01 AM
Help in Chapter 16 aldwincusi VB.NET 2002/2003 Basics 2 June 4th, 2003 09:52 AM





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