Wrox Programmer Forums
|
BOOK: Wrox's Visual Basic 2005 Express Edition Starter Kit ISBN: 978-0-7645-9573-8
This is the forum to discuss the Wrox book Wrox's Visual Basic 2005 Express Edition Starter Kit by Andrew Parsons; ISBN: 9780764595738
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Wrox's Visual Basic 2005 Express Edition Starter Kit ISBN: 978-0-7645-9573-8 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 May 13th, 2006, 08:44 AM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter Seven List Box Population - Again

Chapter 7 P 126 Section 6:
When the application is run and the 'Show List' button is clicked, the list box is NOT populated with the information in the database. Please tell me what is wrong as I can not identify the problem.
I programmed myself following the book and also used your downloaded code to test. Neither display the database in the list box. I started with the Personal Organizer Start project for Chapter 7 in the code download. Also, I can you browse the database in the Database Explorer and see that the tables have data in them. I right click the Person Table in the Data Sources window and choose to Preview the Data. My database table has two records with First Name fields.

Regards,

tewill




 
Old May 18th, 2006, 06:57 AM
Authorized User
 
Join Date: Oct 2005
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Figgis
Default

I didnt notice your post originally and I posted this within Chapert 7 topic. But I have exactly the same problem. "I also have nothing displayed on the List when I run the program. I've tried using the downloaded code as well as the one I created working through the book and I still get nothing displayed. This doesnt seem right to me."


Figgis
 
Old May 29th, 2006, 03:46 PM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem Solved...

All along I felt that the problem was a configuration issue and alas I found the root cause to the program failures! The connection string specified in the application configuration XML file (app.config) did not match the database file location specified in the database properties (PO_Data.mdf) connection string. Because the configuration file had a different path but the same database name the error message indicated “the same name exists, or specified file cannot be opened, or it is located on UNC share."

The problem exists in the VB Express Code download examples beginning with Chapter 7; this is the reason that the List Box fails to populate with names even though the database is connected. However it is also the reason that the example code would not run in Chapter 8 and Chapter 9 and the problem may carry over to the later chapters as well.

Listed below are the two conflicting connection string specifications:

[u]App.Config XML File Connection String</u>:
<connectionStrings>
    <add name="Personal_Organizer.Settings.PO_DataConnectio nString"
            connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;H:\Wile y-2\Wrox Visual Basic Express 2005 Starter Kit\Code\Chapter 9\Personal Organizer Database File\PO-Data.mdf&quot;;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
    </connectionStrings>



[u]PO_Data.mdf Properties Connection String:</u>

Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Documents and Settings\User Name\My Documents\Visual Studio 2005\VB_2005_Express_Code\Chapter 09\Personal Organizer Database File\PO-Data.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True

It appears that the example code was developed on a machine with an ‘H’ drive as the source of the sample files. To resolve the problem I copied over the path in use on my system completely replacing all the text between H:\Wiley-2 and PO_Data.mdf, as shown in the bold text highlighted in the specifications listed above. This action eliminated the SQL Exception error at runtime.

It should be noted however that fixing the connection specification issue does not resolve all remaining code issues. I will provide two examples, the first failure related to null entries in the database when populating the Person Details control in Chapter 7.

Null entries in the database example prevent the Person Details control from being populated and an exception error to be thrown. Both the birth date and the gift categories generate an exception that states ‘Conversion from type 'DBNull' to type 'Date' is not valid’ for database entries with no entry in the field. I resolved this error with the following code revisions highlighted and in bold-italic below:

Module GeneralFunctions
    Public Function GetPerson(ByVal PersonID As Integer) As Person
        Dim GetPersonAdapter As New _PO_DataDataSetTableAdapters.PersonTableAdapter
        Dim GetPersonTable As New _PO_DataDataSet.PersonDataTable
        GetPersonAdapter.Fill(GetPersonTable)
        Dim PersonDataView As DataView = GetPersonTable.DefaultView
        PersonDataView.RowFilter = "ID = " + PersonID.ToString
        With PersonDataView
            If .Count > 0 Then
                Dim objPerson As New Person
                With .Item(0)
                    objPerson.ID = CType(.Item("ID"), Integer)
                    objPerson.FirstName = .Item("NameFirst").ToString.Trim
                    objPerson.LastName = .Item("NameLast").ToString.Trim
                    objPerson.HomePhone = .Item("PhoneHome").ToString.Trim
                    objPerson.CellPhone = .Item("PhoneCell").ToString.Trim
                    objPerson.Address = .Item("Address").ToString.Trim
                    If .Item("DateOfBirth").ToString > "" Then
                        'objPerson.BirthDate = CType(.Item("DateOfBirth"), Date)
                        objPerson.BirthDate = CType(.Item("DateOfBirth"), Date).Date
                    Else
                        objPerson.BirthDate = CType("1/1/1900", Date)
                    End If
                    objPerson.EmailAddress = .Item("EmailAddress").ToString.Trim
                    objPerson.Favorites = .Item("Favorites").ToString.Trim
                    If .Item("GiftCategories").ToString > "" Then
                        'objPerson.GiftCategories = CType(.Item("GiftCategories"), Integer)
                        objPerson.GiftCategories = .Item("GiftCategories")
                    End If
                    objPerson.Notes = .Item("Notes").ToString.Trim
                End With
                Return objPerson
            Else
                Return Nothing
            End If
        End With
    End Function

Note that I left the original code statement included but remarked out so that the changes would be obvious. I hope this find helps others as well! I have also communicated these findings to Andrew Parsons.

tewill


 
Old June 18th, 2006, 06:47 PM
Registered User
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My listbox does not populate and the connection strings are correct. Anyone have any ideas?
 
Old August 12th, 2006, 07:29 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Tewill
Many thanks for your post, it has indeed helped me to overcome that snag in Chapter 7, that has hindered many people working their way through the book.

I followed your advice with caution and indeed I now have data appearing in my list box.

I want to thank you for your contribution, as without this it could have taken me along time to see where the problem is, as I have no one I could ask about this. I am new to programming and get quite distracted with all the intricate coding details required, to be able to stand back and analyse the problem, hopefully this will come with more experience.

Thanks again

jco2007

 
Old August 25th, 2006, 12:38 AM
Registered User
 
Join Date: Aug 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Didn't help me at all and only made it worse.

IMO, the entire book is very nearly useless without some sort of fix.

I keep receiving a CLS-Compliant error.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





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