Wrox Programmer Forums
|
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 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 March 12th, 2005, 01:10 PM
Authorized User
 
Join Date: Mar 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 16 ??

Book: Beginning VB.NET 2nd edition chapter 16 page 647
When I ran the application Binding Simple Controls I got the following error saying" can Not bind to property or column au_lname on datasource" here is part of the code.....
Public Class Form1
    Inherits System.Windows.Forms.Form
    'Declare objects...
    Dim myConnection As OleDbConnection = New OleDbConnection _
    ("provider=Microsoft.jet.oledb.4.0;data source=E:\VB Practice files\BindingExample\PUBS.MDB")
    Dim myAdapter As OleDbDataAdapter = New OleDbDataAdapter( _
    "SELECT authors.au_id, au_lname, au_fname, " & _
    "titles.title_id, title, price " & _
    " FROM authors " & _
    "JOIN titleauthors ON authors.au_id = titleauthor.au_id " & _
    "JOIN titles ON titleauthor.title_id = titles.title_id " & _
    "ORDER BY au_lname, au_fname", myConnection)

    Dim myDS As DataSet
    Dim myDV As DataView
    Dim myCurrencyManager As CurrencyManager

Private Sub BindFields()
        'clear any previous bindings...
        txtLastName.DataBindings.Clear()
        txtFirstName.DataBindings.Clear()
        txtBookTitle.DataBindings.Clear()
        txtPrice.DataBindings.Clear()

        'add new bindings to the dataview object..
        txtLastName.DataBindings.Add("Text", myDV, "au_lname") txtFirstName.DataBindings.Add("Text", myDV, "au_fname")
        txtBookTitle.DataBindings.Add("Text", myDV, "title")
        txtPrice.DataBindings.Add("Text", myDV, "price")

        'display a ready status
        StatusBar1.Text = "Ready"
    End Sub

 
Old March 14th, 2005, 07:02 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I notice that your code is using an Access database and not SQL Server. Open the database using Microsoft Access and verify the column names in the table against the SQL statement in your code to ensure that the column names match.
 
Old March 14th, 2005, 06:32 PM
Authorized User
 
Join Date: Mar 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have already checked the column name and since i am using OleDBdataAdapter, that should have worked,but it seems OleDBdataAdapter won't recognize the syntax, do I need to do any updating? I am using VB.NET standards with Access 2002 and updated Desktop Egnine to MSDE 2000 service pack 3.
Any suggestions?

 
Old March 15th, 2005, 07:10 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I created an Access database that contained the tables from the Pubs database in SQL Server. In order to get the project to run, I had to change the select statement as shown below. Once I did that, I didn't have any problems and all fields were bound to the DataView.

Thearon

        objDataAdapter = New OleDbDataAdapter( _
            "SELECT dbo_authors.au_id, dbo_authors.au_lname, dbo_authors.au_fname, dbo_titles.title_id, dbo_titles.title, dbo_titles.price " & _
            "FROM (dbo_authors INNER JOIN dbo_titleauthor ON dbo_authors.au_id = dbo_titleauthor.au_id) INNER JOIN dbo_titles ON dbo_titleauthor.title_id = dbo_titles.title_id " & _
            "ORDER BY dbo_authors.au_lname, dbo_authors.au_fname;", objConnection)
 
Old March 15th, 2005, 06:25 PM
Authorized User
 
Join Date: Mar 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did re-write the SQl and it worked with the wizard but when I run it with the hard code, I still get the same error here what I got:

Public Class Form1
    Inherits System.Windows.Forms.Form
    'Declare objects...
    Dim myConnection As OleDbConnection = New OleDbConnection _
    ("provider=Microsoft.jet.oledb.4.0;data source=E:\PUBS1.MDB")
    Dim myAdapter = New OleDbDataAdapter( _
    "SELECT authors.au_id, authors.au_lname, authors.au_fname, " & _
    "titles.title_id, titles.title, titles.price " & _
    " FROM (authors INNER JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
    "INNER JOIN titles ON titleauthor.title_id = titles.title_id) " & _
    "ORDER BY authors.au_lname, authors.au_fname", myConnection)

    Dim myDS As DataSet
    Dim myDV As DataView
    Dim myCurrencyManager As CurrencyManager
----------------------------------------------------------
this is where the error show:

 Private Sub BindFields()
        'clear any previous bindings...
        txtLastName.DataBindings.Clear()
        txtFirstName.DataBindings.Clear()
        txtBookTitle.DataBindings.Clear()
        txtPrice.DataBindings.Clear()

        'add new bindings to the dataview object..
        txtLastName.DataBindings.Add("Text", myDV, "au_lname")
        txtFirstName.DataBindings.Add("Text", myDV, "au_fname")
        txtBookTitle.DataBindings.Add("Text", myDV, "title")
        txtPrice.DataBindings.Add("Text", myDV, "price")

        'display a ready status
        StatusBar1.Text = "Ready"
    End Sub
any suggestions???? thanks

 
Old March 16th, 2005, 06:06 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

This may sound like a silly question but are you running the FillDataSetAndView procedure before you run the BindFields procedure? Please verify all procedures are running and in the order that they are supposed to.

One other thing that comes to mind is that you could download the sample code for the book and use that code replacing the connection string and query with yours.

Thearon
 
Old March 16th, 2005, 05:59 PM
Authorized User
 
Join Date: Mar 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I followed the book and changed the connection strings to the database, and yes FillDataSetAndView is before the the BindFields procedure.
I downloaded the codes but Binding example was not included in the chapter.
thanks


 
Old March 17th, 2005, 07:44 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Yes, you are correct, the code is missing from the download. Not to fear though as you can download the code for Beginning VB.Net 2003 and use the BindingExample project from Chapter 16. You'll need to change the namespace from SqlClient to OleDb and change SqlCommand to OleDbCommand and the SqlException to OleDbException. Finally, replace the Connection object and DataAdapter code with your code and you should be good to go.

Thearon
 
Old March 17th, 2005, 06:39 PM
Authorized User
 
Join Date: Mar 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did download the example and made the changes as you said and for the sql I used the INNER JOIN and still I am getting the same error that it can not bind to column au_lname, but when I run it with wizard, it does work.
any ideas why it won't bind. it can't be Access can it? thanks for your support.

 
Old March 18th, 2005, 05:53 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I'm sorry but I'm all out of ideas. I downloaded the sample code and made the changes that I mentioned and the DataView bound to the controls just fine. So now it sounds like it might be a configuration problem of some kind but what I have no idea. Sorry.

Thearon





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 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
Chapter 16 ioda006 JSP Basics 3 August 21st, 2004 07:28 PM
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.