I’m trying to use the MySQLPreparedStatement function for updating a record in the database. I use the exact same BindType and Bind Settings for both this update as well as the insert. The only thing changing is the query itself. The Insert works very well. The update however gives me a nilexception error. I created a straight SQL update statement with the same data as that being send to the prepared statement and ran it through the DB.SQLExecute successfully so I know that the update statement is good. Below are the 2 query strings:
qry = "UPDATE pm_FormData SET ProdCode = ?, Desc1 = ?, Desc2 = ?, ProdCat = ?, AlphaName = ?, " _
- " SC1 = ?, SC2 = ?, SC3 = ?, SC4 = ?, SC5 = ?, SC6 = ?, SC7 = ?, SC8 = ?, SC9 = ?, SC10 = ?, " _
- " SC11 = ?, SC12 = ?, SC13 = ?, " _
- " SC14 = ?, SC15 = ?, SC16 = ?, ProcessCode = ?, CatchWeight = ?, CaseWeight = ?, PackSize = ?, " _
- " Barcode = ?, BlockTi = ?, TierHi = ?, StockUM = ?, PricingUM = ?, SellByUM = ?, AlternateUM = ?, DivID = ?, " _
- " Requestor = ?, EnterBy = ?, Complete = ?, RequestDate = ? WHERE ID = " + str(prodObj.ID)
dim dbgQry As String
dbgQry = “UPDATE pm_FormData SET ProdCode = '” + prodObj.ProdCode + “’, Desc1 = '” + prodObj.Desc1 _
- “’, Desc2 = '” + prodObj.Desc2 + “’, ProdCat = '” + prodObj.ProdCat + “’, AlphaName = '” _
- prodObj.AlphaName + “’, SC1 = '” + prodObj.SC1 + “’, SC2 = '” + prodObj.SC2 + “’, SC3 = '” _
- prodObj.SC3 + “’, SC4 = '” + prodObj.SC4 + “’, SC5 = '” + prodObj.SC5 + “’, SC6 = '” + prodObj.SC6 _
- “’, SC7 = '” + prodObj.SC7 + “’, SC8 = '” + prodObj.SC8 + “’, SC9 = '” + prodObj.SC9 + “’, SC10 = '” _
- prodObj.SC10 + “’, SC11 = '” + prodObj.SC11 + “’, SC12 = '” + prodObj.SC12 + “’, SC13 = '” + prodObj.SC13 _
- “’, SC14 = '” + prodObj.SC14 + “’, SC15 = '” + prodObj.SC15 + “’, SC16 = '” + prodObj.SC16 _
- "’, ProcessCode = " + str(prodObj.ProcessCode) + “, CatchWeight = '” + prodObj.CatchWeight _
- "’, CaseWeight = " + str(prodObj.CaseWeight) + “, PackSize = '” + prodObj.PackSize + “’, Barcode = '” + prodObj.Barcode _
- "’, BlockTi = " + str(prodObj.BlockTi) + ", TierHi = " + str(prodObj.TierHi) + “, StockUM = '” + prodObj.StockUM _
- “’, PricingUM = '” + prodObj.PricingUM + “’, SellByUM = '” + prodObj.SellByUM + “’, AlternateUM = '” _
- prodObj.AlternateUM + "’, DivID = " + str(prodObj.DivID) + “, Requestor = '” + prodObj.Requestor _
- “’, EnterBy = '” + prodObj.EnterBy + “’, Complete = '” + prodObj.Complete + “’, RequestDate = '” _
- str(prodObj.RequestDate) + "’ WHERE ID = " + str(prodObj.ID)
I can not figure out while the NilObjectException is being thrown. Below are the Binding Statements. The binding statements are in a Method which is part of the prodObj class. When I use this Method for both the Insert and the the Update. The insert work perfectly.
dim ps As PreparedSQLStatement
dim p As cProduct = prodObj
ps = Session.AppDb.Prepare(query)
ps.Bindtype(0, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(0, p.ProdCode)
ps.Bindtype(1, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(1, p.Desc1)
ps.Bindtype(2, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(2, p.Desc2)
ps.Bindtype(3, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(3, p.ProdCat)
ps.Bindtype(4, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(4, p.AlphaName)
ps.Bindtype(5, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(5, p.SC1)
ps.Bindtype(6, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(6, p.SC2)
ps.Bindtype(7, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(7, p.SC3)
ps.Bindtype(8, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(8, p.SC4)
ps.Bindtype(9, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(9, p.SC5)
ps.Bindtype(10, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(10, p.SC6)
ps.Bindtype(11, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(11, p.SC7)
ps.Bindtype(12, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(12, p.SC8)
ps.Bindtype(13, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(13, p.SC9)
ps.Bindtype(14, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(14, p.SC10)
ps.Bindtype(15, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(15, p.SC11)
ps.Bindtype(16, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(16, p.SC12)
ps.Bindtype(17, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(17, p.SC13)
ps.Bindtype(18, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(18, p.SC14)
ps.Bindtype(19, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(19, p.SC15)
ps.Bindtype(20, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(20, p.SC16)
ps.Bindtype(21, MySQLPreparedStatement.MYSQL_TYPE_LONG)
ps.Bind(21, p.ProcessCode)
ps.Bindtype(22, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(22, p.CatchWeight)
ps.Bindtype(23, MySQLPreparedStatement.MYSQL_TYPE_FLOAT)
ps.Bind(23, p.CaseWeight)
ps.Bindtype(24, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(24, p.PackSize)
ps.Bindtype(25, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(25, p.Barcode)
ps.Bindtype(26, MySQLPreparedStatement.MYSQL_TYPE_SHORT)
ps.Bind(26, p.BlockTi)
ps.Bindtype(27, MySQLPreparedStatement.MYSQL_TYPE_SHORT)
ps.Bind(27, p.TierHi)
ps.Bindtype(28, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(28, p.StockUM)
ps.Bindtype(29, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(29, p.PricingUM)
ps.Bindtype(30, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(30, p.SellByUM)
ps.Bindtype(31, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(31, p.AlternateUM)
ps.Bindtype(32, MySQLPreparedStatement.MYSQL_TYPE_SHORT)
ps.Bind(32, p.DivID)
ps.Bindtype(33, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(33, p.Requestor)
ps.Bindtype(34, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(34, p.EnterBy)
ps.BindType(35, MySQLPreparedStatement.MYSQL_TYPE_STRING)
ps.Bind(35, p.Complete)
ps.BindType(36, MySQLPreparedStatement.MYSQL_TYPE_DATE)
ps.Bind(36, p.RequestDate)
ps.SQLExecute()
Session.AppDb.SQLExecute(“COMMIT”)
Is there any way to get deeper into the NilObjectException to see why the error is being thrown?