p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 6th, 2009, 12:31 PM
Authorized User
Points: 202, Level: 4
Points: 202, Level: 4 Points: 202, Level: 4 Points: 202, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 44
Thanks: 1
Thanked 0 Times in 0 Posts
Default DataGrid and the WDA Base Class

I am trying to use the WDABase class with the DataGrid example in chapter 5 but am having a problem getting it to work. The following example is slightly different then the example in chapter 5. The code throws the error "Object reference not set to an instance of an object." at the line "objData.Command.CommandText = "Query1" in the event NonParameterQuery"

Code:
 
PublicClass Form1
Private Sub PopulateGrid()
'Initialize a new instance of the WDABase data class
Using objData As New WDABase
Try
'Populate the DataSet
objData.DataAdapter.Fill(objData.DataSet, "DataGrid")
'Bind the data to the dataset
dgrd1.DataSource = objData.DataSet
'The data member is the table name
dgrd1.DataMember = "tGrid"
'Set the Alternating RowsDefaultCellStyle.BackColor
dgrd1.AlternatingRowsDefaultCellStyle.BackColor = Color.WhiteSmoke
'Set theCellBorderStyle property
dgrd1.CellBorderStyle = DataGridViewCellBorderStyle.Raised
'Set the SelectionMode property
dgrd1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
'Set the AutoSizeColumnsMode property
dgrd1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
'Center align the State columnn
dgrd1.Columns("State").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Using
End Sub
Private Sub NonParameterQuery()
'Initialize a new instance of the WDABase data class
Using objData As New WDABase
objData.Command.CommandText = "Query1"
objData.Command.CommandType = CommandType.StoredProcedure
objData.Command.Connection = objData.Connection
'PopulateGrid the data grid
PopulateGrid()
End Using
End Sub
Private Sub ParameterQuery()
'Initialize a new instance of the WDABase data class
Using objData As New WDABase
objData.Command.CommandText = "Query2"
objData.Command.CommandType = CommandType.StoredProcedure
'PopulateGrid the data grid
PopulateGrid()
End Using
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
NonParameterQuery()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ParameterQuery()
End Sub
EndClass







Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old May 9th, 2009, 08:20 AM
Thearon's Avatar
Wrox Author
Points: 1,228, Level: 13
Points: 1,228, Level: 13 Points: 1,228, Level: 13 Points: 1,228, Level: 13
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 381
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Does your WDABase class initialize the Command object when the class is initialized? From the code that you have posted that is inferred.

Thearon
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old May 13th, 2009, 02:49 PM
Authorized User
Points: 202, Level: 4
Points: 202, Level: 4 Points: 202, Level: 4 Points: 202, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 44
Thanks: 1
Thanked 0 Times in 0 Posts
Default DataGrid and the WDA Base Class

Thearon, thank you for the reply.

Unless I misunderstood thr code, this initializes the Command object in the EDABase class:

PublicSub InitializeCommand()
If Command IsNothingThen
Try
Command = New OleDbCommand(SQL, Connection)
'See if this is a stored procedure
IfNot SQL.ToUpper.StartsWith("SELECT ") _
AndNot SQL.ToUpper.StartsWith("INSERT ") _
AndNot SQL.ToUpper.StartsWith("UPDATE ") _
AndNot SQL.ToUpper.StartsWith("DELETE ") Then
Command.CommandType = CommandType.StoredProcedure
EndIf
Catch OleDbExceptionErr As OleDbException
ThrowNew System.Exception(OleDbExceptionErr.Message, _
OleDbExceptionErr.InnerException)
EndTry
EndIf
EndSub

I get the error at this line of code:
objData.Command.CommandText = "Query1"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old June 23rd, 2009, 07:49 AM
Thearon's Avatar
Wrox Author
Points: 1,228, Level: 13
Points: 1,228, Level: 13 Points: 1,228, Level: 13 Points: 1,228, Level: 13
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 381
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Have you tried setting a breakpoint in the InitializeCommand procedure to ensure that the Command object is being initialized. If so then step through the code from that point until you set it to your query to make sure no other call is being made to set that object to Nothing.

Thearon
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Base Class for Code-Behind Problem groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 8th, 2004 06:06 AM
classes :: base class is inaccessible .... Kaliste C# 3 July 16th, 2004 05:56 AM
base class inheritance krunch97 VB.NET 2002/2003 Basics 6 April 23rd, 2004 12:48 PM
Page_Load override with base page class nebrown1 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 August 31st, 2003 05:45 AM
Help with DBObject base class projectedNexus BOOK: ASP.NET Website Programming Problem-Design-Solution 1 August 12th, 2003 07:36 PM



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


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc