UpdateCommand Error

mechwarrior3

Well-known member
Joined
Dec 19, 2005
Messages
67
Programming Experience
Beginner
Well, it looks like I'm back to report that I have encountered another error. I don't know where this one has come from but I have no idea what to do. Remember that primary key error I was encountering? (http://www.vbdotnetforums.com/showthread.php?t=10946)

Well, my code was working fine until I tried running it today. Annoying how that sometimes happens, eh?

Okay, sorry, I digress. In any case, my code is no longer working. What my code is doing is inserting and updating records within a database depending on whether or not that record exists. If it does not, it is inserted and if the record does exist, it is updated. Here is what my code looks like (EDIT: All of the green code is actual code, something just got screwed up when I pasted my code in):

VB.NET:
[SIZE=2]strCommand = "UPDATE tbl_HCI_Lot_Inspection_Data SET strArcTube = ?, strDebindDate = ?," _
& " strPrefireDate = ?, strFinalfireDate = ?, strInspectionDate = ?," _
& " ysnReclaimed = ?, nLotGross = ?, nLotNet = ?," _
& " strIntendedCustomer = ?, nVIGross = ?, intWSDefectives = ?," _
& " intCEGGDefectives = ?, intOPDefectives = ?, intBSDefectives = ?," _
& " intRSDefectives = ?, intVoidDefectives = ?, intTearOutDefectives = ?," _
& " intChipDefectives = ?, intScratchDefectives = ?, intCrackDefectives = ?," _
& " intFlashDefectives = ?, intGrayDefectives = ?, intJointDefectives = ?," _
& " intOther1Defective = ?, intOther2Defective = ?, intOther3Defective = ?," _
& " intVisualDefectsNET = ?, nPinTestGross = ?, intCoaxPinDefectives = ?," _
& " int5mmPinDefectives = ?, intCapIDPinDefectives = ?, intNoInsPinDefectives = ?," _
& " intFFUHatDefectives = ?, intFFUPinDefectives = ?, intPinTestNET = ?," _
& " nWSGross = ?, nBSGross = ?, nRSGross = ?," _
& " nVoidGross = ?, nTearOutGross = ?, nCrackGross = ?," _
& " nODChipGross = ?, nIDChipGross = ?, nScratchGross = ?," _
& " nCEGGGross = ?, nOPGross = ?, nFlashGross = ?," _
& " nGrayGross = ?, nJointGross = ?, nOther1Gross = ?," _
& " nOther2Gross = ?, nOther3Gross = ?, intTransferred = ?," _
& " nCoaxPinGross = ?, n5mmPinGross = ?, nCapIDPinGross = ?," _
& " nNoInsPinGross = ?, nFFUHatGross = ?, nFFUPinGross = ?," _
& " nDimsLongGross = ?, nDimsShortGross = ?," _
& " nDimsBigODGross = ?, nDimsSmallODGross = ?," _
& " nDimsBigCapODGross = ?, nDimsSmallCapODGross = ?," _
& " strPartNum = ?, nRegrind = ?, strEmployeeID = ?, strPowderLot = ?," _
& " strOleicAcidLot = ?, strWaxLot = ?, nFFUGross = ?, intFFUNet = ?, nDimsGross = ?," _
& " intDimensionsNET = ?, intLongDefectives = ?, intShortDefectives = ?, intBigODDefectives = ?," _
& " intSmallODDefectives = ?, intBigCapODDefectives = ?, intSmallCapODDefectives = ?" _
& " WHERE strMixID = ? AND strLotNumber = ?"
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] AccessConn [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbConnection(MYACCESSCONN) [/SIZE][SIZE=2][COLOR=#008000]' Main Access Database connection[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] AccessCommand [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbCommand(strCommand)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] AccessDataSet [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.DataSet
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] AccessAdapter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbDataAdapter[/SIZE]
 
[SIZE=2][SIZE=2]AccessAdapter.SelectCommand = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbCommand("SELECT * FROM tbl_HCI_Lot_Inspection_Data WHERE strMixID = ? AND strLotNumber = ?", AccessConn)
AccessAdapter.SelectCommand.Parameters.Add("@MixNum", OleDb.OleDbType.VarChar, 50, "strMixID").Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtMixLotNum.Text
AccessAdapter.SelectCommand.Parameters.Add("@MfgNum", OleDb.OleDbType.VarChar, 50, "strLotNumber").Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtMfgLotNum.Text
AccessAdapter.UpdateCommand = AccessCommand
AccessAdapter.UpdateCommand.Connection = AccessConn
AccessAdapter.UpdateCommand.Parameters.Add("@ArcNum", OleDb.OleDbType.VarChar, 50, "strArcTube")
AccessAdapter.UpdateCommand.Parameters.Add("@DBDate", OleDb.OleDbType.VarChar, 50, "strDebindDate")
AccessAdapter.UpdateCommand.Parameters.Add("@PSDate", OleDb.OleDbType.VarChar, 50, "strPreFireDate")
AccessAdapter.UpdateCommand.Parameters.Add("@SDate", OleDb.OleDbType.VarChar, 50, "strFinalFireDate")
...
 
[SIZE=2]AccessAdapter.Fill(AccessDataSet, "tbl_HCI_Lot_Inspection_Data")
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] AccessDataRow [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow = AccessDataSet.Tables("tbl_HCI_Lot_Inspection_Data").Rows(0)
AccessDataRow("strArcTube") = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtArcTubeType.Text
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtDebindDate.Text = "") [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dteDebindDate = #1/1/0100#
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]dteDebindDate = DateTime.Parse([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtDebindDate.Text)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]AccessDataRow("strDebindDate") = dteDebindDate
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPreSinDate.Text = "") [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dtePresinDate = #1/1/0100#
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]dtePresinDate = DateTime.Parse([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPreSinDate.Text)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]AccessDataRow("strPreFireDate") = dtePresinDate
...
[/SIZE][/SIZE][/SIZE][/SIZE][/COLOR][/SIZE][/SIZE]


This fills in the entire DataRow and after, my code tries to run this line which has worked up until today:

VB.NET:
[SIZE=2][COLOR=black]AccessAdapter.UpdateCommand =[/COLOR] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] [COLOR=black]OleDb.OleDbCommandBuilder(AccessAdapter).GetUpdateCommand[/COLOR][/SIZE]

It's at this line that I get the attached error. How do I fix this? Any suggestions are greatly appreciated.

Thanks, guys. :)

EDIT #2: Apparently, this error occurs when there is no primary key within the database/datatable (Debugging would figure out which one specifically), so now I wonder, is there anyway to use my code and making it work without putting a primary key in the database/datatable?
 

Attachments

  • UpdateCommandError.JPG
    UpdateCommandError.JPG
    19.3 KB · Views: 61
Back
Top