Wrox Programmer Forums
|
BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7
This is the forum to discuss the Wrox book Beginning Microsoft Visual Basic 2008 by Thearon Willis, Bryan Newsome; ISBN: 9780470191347
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 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 30th, 2009, 02:39 PM
Authorized User
 
Join Date: Aug 2005
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default Chapter17 Populating The DataGrid

I am trying to populate a DataGrid using an Access 2000 database.

The example in Chapter 17 was for SQL Server so I modified the code and when I run the project, the grid is visible but not populated. Here's the code that I am using:

Imports System.Data
Imports System.Data.OleDb
PublicClass Form1
Dim objConnection AsNew OleDbConnection _
(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Program Files\My Library\My Library.mdb")
Dim objDataAdapter AsNew OleDbDataAdapter
Dim objDataSet AsNew DataSet
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
objDataAdapter.SelectCommand =
New OleDbCommand
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = _
"SELECT [Title], [Author]" & _
"FROM(tMyLibrary)ORDER BY [Title];"
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objConnection.Open()
objDataAdapter.Fill(objDataSet,
"tMyLibrary")
objConnection.Close()
grdAuthorTitles.AutoGenerateColumns =
True
grdAuthorTitles.DataSource = objDataSet
grdAuthorTitles.DataMember =
"tMyLibrary"
objDataAdapter = Nothing
objConnection = Nothing
EndSub

Can anyone give me any suggestions as to where I went wrong?

Milt
 
Old May 30th, 2009, 04:44 PM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default Chapter 17 ...

I'm not sure but it may be woth trying spaces in your S.Q.L. i.e SELECT ..... ] FROM ..... between arguments, passed to statement. See what happens.
The Following User Says Thank You to liamfitz For This Useful Post:
sirmilt (May 31st, 2009)
 
Old July 1st, 2009, 12:41 PM
Wrox Author
 
Join Date: Mar 2006
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Try this

"SELECT [Title], [Author] "
& _
"FROM tMyLibrary ORDER BY [Title];"

Bryan
 
Old July 2nd, 2009, 03:04 PM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default repopulating existing grid

I'm working on it at the moment, in my own program...... Give me a few days, maybe.
 
Old July 2nd, 2009, 07:00 PM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default populating your datagrid

Instead of setting the 'command object type' in the following statement as a ' New OleDbCommand ', try, ' New SqlCommand '. I'm trying this myself at the moment ! That's how it appears in V.B. 2008 Programmer's Reference. Hope it works.

objDataAdapter.SelectCommand = New OleDbCommand





Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: DATAGRID POPULATING emeka VB Databases Basics 0 April 28th, 2007 08:06 PM
Populating DataGrid emeka VB Databases Basics 0 April 28th, 2007 07:13 PM
Populating dropdown within a datagrid ninel ASP.NET 2.0 Professional 2 May 31st, 2006 02:41 AM
Populating dropdown within a datagrid ninel ASP.NET 2.0 Basics 7 May 26th, 2006 03:26 PM
Populating dropdown within a datagrid ninel General .NET 0 May 26th, 2006 12:27 PM





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