I'm having a wierd problem with ADO.NET in the Compact Framwork on a Pocket PC running Windows Mobile 2003. The code below shows my attempt to insert a record into a SQL Server DB using parameters. For most of my database activity I've just used SQL statements and ExecuteNonQuery, but one of the fields in this table is a binary file, so I'm using parameters. If there's another way to do that, I'm open to that as well.

Anyway the error I'm getting is 'Incorrect Syntax near 'woNumber'' on the Update statement. I can't see anything wrong with the SQL statement as I wrote it. I don't know what this means, but I changed the case of some of the letters in 'WONumber' in the three places it shows in the CommndText statement and the Parameter.Add statement. The one that's showing in the error message is the first instance in the Parameter.Add statement. I guess I assumed ADO.NET constructed a standard SQL INSERT statement, which would only have the word 'WONumber' in there once. I don't get it. By the way, this code was copied from a standard VB.NET app that I wrote to maintain this database and it works fine there. I only changed the SQLClient stuff. Can anyone help? I've been struggling with this for two days.

Here's the code:


aRow = SqlDS.Tables("TKItemImage").NewRow
aRow("WONumber") = SqlDS.Tables("tkworkorders").Rows(iWOIndex).Item("WONumber")
aRow("TicketNumber") = SqlDS.Tables("tkworkorders").Rows(iWOIndex).Item("TicketNumber")
aRow("Item") = Trim(SqlDS.Tables("tkitems").Rows(iItemIndex).Item("Item"))
aRow("Image") = GetPhoto(cParam)
aRow("ImageID") = intID
aRow("ItemID") = SqlDS.Tables("tkitems").Rows(iItemIndex).Item("RowID")
SqlDS.Tables("TKItemImage").Rows.Add(aRow)

SqlCmd.Parameters.Clear()
Dim pPc As SqlClient.SqlParameterCollection = SqlCmd.Parameters

pPc.Add("woNumber", SqlDbType.Int, 0, "WoNumber")
pPc.Add("ticketnumber", SqlDbType.Int, 0, "TicketNumber")
pPc.Add("Item", SqlDbType.Char, 0, "Item")
pPc.Add("Image", SqlDbType.Binary, 0, "Image")
pPc.Add("ImageID", SqlDbType.Int, 0, "ImageID")
pPc.Add("ItemID", SqlDbType.Int, 0, "ItemID")

SqlCmd.CommandText = "INSERT INTO TKItemImage (WONumber, TicketNumber, Item, " & _
"Image, ImageID, ItemID) VALUES (?,?,?,?,?,?)"

SqlAdap.InsertCommand = SqlCmd
SqlAdap.InsertCommand.Connection = SqlConn
SqlAdap.Update(SqlDS, "TKItemImage")
SqlDS.Tables("TKItemImage").AcceptChanges()