p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 (http://p2p.wrox.com/forumdisplay.php?f=34)
-   -   chapter 16 ?? (http://p2p.wrox.com/showthread.php?t=26761)

farsfar2 March 12th, 2005 01:10 PM

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


Thearon March 14th, 2005 07:02 AM

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.

farsfar2 March 14th, 2005 06:32 PM

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?


Thearon March 15th, 2005 07:10 AM

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)

farsfar2 March 15th, 2005 06:25 PM

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


Thearon March 16th, 2005 06:06 AM

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

farsfar2 March 16th, 2005 05:59 PM

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



Thearon March 17th, 2005 07:44 AM

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

farsfar2 March 17th, 2005 06:39 PM

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.


Thearon March 18th, 2005 05:53 AM

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


All times are GMT -4. The time now is 03:42 AM.

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