Why do I get an object reference error?

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
Can someone explain please why I get a oject reference not set to error with the code listed?

From what I can see I am setting it to an object in line two?

VB.NET:
glb_cnMM2007.Open()

glb_taTransactions = New SqlClient.SqlDataAdapter

glb_taTransactions.SelectCommand.Connection = glb_cnMM2007


Thanks
 
Easy.

I'd say your dataAdapter has also got Insert, Delete and Modify commands.

Therefore you need

VB.NET:
glb_cnMM2007.Open()
 
glb_taTransactions = New SqlClient.SqlDataAdapter
 
glb_taTransactions.SelectCommand.Connection = glb_cnMM2007
glb_taTransactions.InsertCommand.Connection = glb_cnMM2007
glb_taTransactions.UpdateCommand.Connection = glb_cnMM2007
glb_taTransactions.DeleteCommand.Connection = glb_cnMM2007

HTH
 
why dont you just use the debugger to find it? your code crashes because of this error so it breaks at the point the error occurs...

just point to words on screen, until the tooltip says "Nothing"
meaning that the object reference points to nothing

my bets are on glb_taTransactions.SelectCommand being Nothing
 
Back
Top