Wrox Programmer Forums
|
BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 Databases by Thearon Willis; ISBN: 9780764588945
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 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 1st, 2008, 08:18 PM
Registered User
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5 Exercises Creating a non-Parameter Query

I cannot find where the missing parameter is in my code that invokes the Try - Catch MessageBox Error in the Private Sub "PopulateGrid()". THe error message reads "Too few parameters. Expect 1." I have tried copy and pasting to eliminate the typo issue to no avail. THanks[email protected]Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    'Form level variables
    Private strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Documents and Settings\Marianne\Desktop\DBPTT\ProjectTimeTracker .mdb;"

    Private objConnection As OleDbConnection
    Private objCommand As OleDbCommand
    Private objDataAdapter As OleDbDataAdapter
    Private objDataSet As DataSet


    Private Sub PopulateGrid()
        'Initialize a new instance of the OleDbDataAdapter class
        objDataAdapter = New OleDbDataAdapter

        'Initialize a new instance of the DataSet class
        objDataSet = New DataSet

        'Set the SelectCommand for the OleDbDataAdapter
        objDataAdapter.SelectCommand = objCommand

        Try
            'Populate the DataSet
            objDataAdapter.Fill(objDataSet, "Projects")

            'Bind the DataSet to the DataGrid
            grdResults.DataSource = objDataSet
            grdResults.DataMember = "Projects"

            'Set the AlternatingRowsDefaultCellStyle.BackColor property
            grdResults.AlternatingRowsDefaultCellStyle.BackCol or = Color.WhiteSmoke

            'Set the CellBorderStyle property
            grdResults.CellBorderStyle = DataGridViewCellBorderStyle.None

            'Set the SelectionMode property
            grdResults.SelectionMode = DataGridViewSelectionMode.FullRowSelect

            'Set the AutoSizeColumnsMode property
            grdResults.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells

            'Right align SequenceNumber column
            grdResults.Columns("SequenceNumber").DefaultCellSt yle.Alignment = DataGridViewContentAlignment.MiddleRight

        Catch OleDbException As OleDbException
            MessageBox.Show(OleDbException.Message, "Access Queries")
        End Try

        'Cleanup
        objCommand.Dispose()
        objCommand = Nothing
        objDataAdapter.Dispose()
        objDataAdapter = Nothing
        objDataSet.Dispose()
        objDataSet = Nothing
        objConnection.Dispose()
        objConnection = Nothing
    End Sub

    Private Sub btnNonParameterQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNonParameterQuery.Click
        'Initialize a new instance of the OleDbConnection class
        objConnection = New OleDbConnection(strConnectionString)

        'Initialize a new instance of the OleDbCommand class
        objCommand = New OleDbCommand

        'Set the objCommand object properties
        objCommand.CommandText = "usp_SelectProjects"
        objCommand.CommandType = CommandType.StoredProcedure
        objCommand.Connection = objConnection

        'Populate the DataGridView
        Call PopulateGrid()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class







Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 exercises Dwayne BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 9 January 8th, 2009 06:40 PM
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM





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