Update Table statement causing error
|
|
Thread rating:  |
David Phelan - 09 Sep 2004 16:51 GMT Group,
I am very confused by the error I'm getting when trying to execute an update statement using the Connection.Execute method.
Basically, I'm keeping a list of files and attributes in an Access database. When I run the script that checks the files and updates the DB with any changes, the update statement fails with the error:
"Syntax error in update statement"
The thing is, I know that the statement is correct. I even pasted the statement into an Access query window and ran it with no errors.
I have tried using the recordset.update method also. This does not produce an error, but it also does not update the DB regardless of whether I update the fields value and then call the update method or I supply the fieldname and value to the update method. Altering the field value sets the editmode to EditInProgress, but the update method never commits the change.
I am only in develpoment stages so I know there is no one else accessing the DB and I can see no reason why these statements would fail.
An example failing statement is:
update tblfiles set size=6590508 where fileid=222
I am using VB6 SP6, ADO 2.7, Access2k SP3 and WinXP SP1.
Any thoughts?
Dave
Veign - 09 Sep 2004 17:36 GMT Post the actual code and the copy and paste SQL Statement. Also, include what the field types are in the database that you are trying to update.
 Signature Chris Hanscom MVP (Visual Basic) http://www.veign.com --
> Group, > [quoted text clipped - 29 lines] > > Dave David Phelan - 09 Sep 2004 18:28 GMT Public Sub AddFiles(FilePath As String)
Dim arFileList() As DFiles Dim I As Integer, x As Integer Dim Cnn As Connection Dim Rst As Recordset Dim f As Integer, d As Integer Dim arTypes() As String Dim strSQL As String
f = 0 d = 0
Set Cnn = CreateConnection(ADO_MSAccess, App.Path & "\webfiles.mdb") Cnn.Open Set Rst = New ADODB.Recordset Rst.LockType = adLockOptimistic Rst.CursorType = adOpenKeyset Rst.CursorLocation = adUseClient arTypes = Split(FileTypes, "|") For I = 0 To UBound(arTypes) ReDim arFileList(0) FindFilesAPI FilePath, "*" & arTypes(I), f, d, arFileList For x = 0 To UBound(arFileList) If arFileList(x).Path <> "" Then Rst.Open "select * from tblfiles where path='" & arFileList(x).Path & Replace(arFileList(x).Name, "'", "''") & "'", Cnn, adOpenDynamic, adLockBatchOptimistic If Rst.EOF Then With arFileList(x) With arFileList(x) Cnn.Execute "insert into tblfiles (filename,path,type,size,created,modified) values('" _ & .Name & "','" & .Path & "\" & Replace(.Name, "'", "''") & "','" & .FileType & "'," & .Size & ",#" & .CreationDate & "#,#" & .ModDate & "#)" End With End With Else If arFileList(x).Size <> Rst!Size Then Cnn.Execute "update tblfiles set size=" & CLng(arFileList(x).Size) & " where songid=" & Rst!songid ElseIf arFileList.ModDate <> Rst!modified Then Cnn.Execute "update tblfiles set modified=#" & arFileList(x).ModDate & "# where fileid=" & Rst!fileid End If End If Rst.Close End If Next x Next I
On Error Resume Next Rst.Close Cnn.Close Set Rst = Nothing Set Cnn = Nothing Set Ctl = Nothing
End Sub
Table Def
FileName Text Path Text Type Text Size Long Created Date Modified Date
Failing Query Statement
update tblfiles set size=6590508 where fileid=222
> Post the actual code and the copy and paste SQL Statement. Also, include > what the field types are in the database that you are trying to update. Veign - 09 Sep 2004 19:35 GMT Try changing this: "insert into tblfiles (filename,path,type,size,created,modified)
to this "insert into tblfiles (filename,[path],[type],[size],[created],[modified])
As I think you are using field names that are reserved words (type and size). I surrounded others with the [] just to fully test.
 Signature Chris Hanscom MVP (Visual Basic) http://www.veign.com --
> Public Sub AddFiles(FilePath As String) > [quoted text clipped - 22 lines] > If arFileList(x).Path <> "" Then > Rst.Open "select * from tblfiles where path='" & arFileList(x).Path & Replace(arFileList(x).Name, "'", "''") & "'", Cnn, adOpenDynamic, adLockBatchOptimistic
> If Rst.EOF Then > With arFileList(x) > With arFileList(x) > Cnn.Execute "insert into tblfiles (filename,path,type,size,created,modified) values('" _ > & .Name & "','" & .Path & "\" & Replace(.Name, "'", "''") & "','" & .FileType & "'," & .Size & ",#" & .CreationDate & "#,#" & .ModDate & "#)"
> End With > End With [quoted text clipped - 34 lines] > > Post the actual code and the copy and paste SQL Statement. Also, include > > what the field types are in the database that you are trying to update. David Phelan - 09 Sep 2004 20:07 GMT The insert works just fine, its the update statements that fail.
> Try changing this: > "insert into tblfiles (filename,path,type,size,created,modified) [quoted text clipped - 5 lines] > As I think you are using field names that are reserved words (type and > size). I surrounded others with the [] just to fully test. David Phelan - 09 Sep 2004 20:22 GMT Well, although there was no problem on the insert statement, for whatever reason, I applied your suggestion to the update statement and it fixed the problem. Thank you very much, I hadn't event thought about reserved words.
Dave
> Try changing this: > "insert into tblfiles (filename,path,type,size,created,modified) [quoted text clipped - 5 lines] > As I think you are using field names that are reserved words (type and > size). I surrounded others with the [] just to fully test. Veign - 10 Sep 2004 00:09 GMT Glad its fixed...
 Signature Chris Hanscom MVP (Visual Basic) http://www.veign.com --
> Well, although there was no problem on the insert statement, for whatever > reason, I applied your suggestion to the update statement and it fixed the [quoted text clipped - 11 lines] > > As I think you are using field names that are reserved words (type and > > size). I surrounded others with the [] just to fully test. David Wier - 29 Oct 2004 19:04 GMT I know 'size' is an ODBC reserved keyword It's always best to NOT create field or table names from reserved keywords, however, as you've found, surrounding them with square brackets in your SQL statements is how to get around it, when you already have them in place.
David Wier MCP, MVP ASP.NET, ASPInsider http://aspnet101.com http://aspexpress.com
> Well, although there was no problem on the insert statement, for whatever > reason, I applied your suggestion to the update statement and it fixed the [quoted text clipped - 11 lines] > > As I think you are using field names that are reserved words (type and > > size). I surrounded others with the [] just to fully test.
|
|
|