Solved

SQL Query Error

Posted on 2004-10-04
19
242 Views
Last Modified: 2010-04-17
I have created an inventory program but have run into some troubles when updating the database. The user pulls data from one msflexgrid (parent category), and the inventory items with the same description are displayed on a second msflexgrid (child). When the user clicks on the second msflexgrid, the data is dropped into text boxes for edititing. However, when the user presses the "update" command button I keep getting an SQL Query error. Could someone please look at my code and show me what I have done wrong.. thanks in advance!

Case "UPDATE"
   
        If IsValidData = True Then
       
        Select Case strCategory
       
            Case "MOTHERBOARD"
                         
               strMySQL = "UPDATE tblDataChild.* SET " & " tblDataChild.[ItemDescription]='" & Trim(Me.txtItemDescription.Text) & "'" & " tblDataChild.[ItemMOBOID]='" & Trim(Me.txtMoboID.Text) & "'" & " tblDataChild.[ItemLocation]='" & Trim(Me.txtLocation.Text) & "'" & " tblDataChild.[ItemOwner]= '" & Trim(Me.dcbOwner.Text) & "'" & " tblDataChild.[ItemStatus]='" & Trim(Me.dcbStatus.Text) & "'" & " tblDataChild.[ItemRemovedDate]='" & Trim(Me.txtItemRemovedDate.Text) & "'" & " WHERE tblDataChild.[ID]='" & Trim(Me.txtID.Text) & "'"""
                                           
                Set UpdateDB = New ADODB.Connection
                UpdateDB.ConnectionString = dbConString
                UpdateDB.mode = adModeReadWrite
                UpdateDB.Open
                UpdateDB.Execute strMySQL, adExecuteNoRecords
                UpdateDB.Close
                 
                SSTab1.Tab = 1
                Me.txtMoboID.Locked = False
                Me.txtMoboID.Enabled = True
                Me.lblMoboID.Enabled = True
           
                With MSFlexGrid2
                For i = 0 To .Rows - 1
                    For j = 0 To .Cols - 1
                        .Row = i
                        .Col = j
                        If .Text = "" Then
                            .Text = "  " & i & " " & j
                            .Text = "  "
                        End If
                    Next j
                Next i
                   
            End With
           
            mode = adModeReadWrite
            loc = adUseClient
           
            ConnectToDB mode, loc, dbConString
       
            Set rs = New ADODB.Recordset
           
            rs.Open "SELECT * FROM tblDataChild", DbCon, adOpenForwardOnly, adLockOptimistic
            mystring = "|MOBO ID|INVENTORY ITEM|STORAGE LOCATION|OWNER|STATUS|"
            MSFlexGrid2.FormatString = mystring
            MSFlexGrid2.ColWidth(0) = 0
            MSFlexGrid2.ColWidth(1) = 775
            MSFlexGrid2.ColWidth(2) = 2700
            MSFlexGrid2.ColWidth(3) = 1700
            MSFlexGrid2.ColWidth(4) = 700
            MSFlexGrid2.ColWidth(5) = 2200
            MSFlexGrid2.ColWidth(6) = 0
            MSFlexGrid2.ColWidth(7) = 0
            MSFlexGrid2.Rows = 1
           
            If rs.RecordCount > 0 Then
                rs.MoveFirst
                           
                If Not rs.EOF Then
                    x = 0
                    Do While Not rs.EOF
                        MSFlexGrid2.Rows = MSFlexGrid2.Rows + 1
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 0) = rs.Fields("ID")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 1) = rs.Fields("ItemMOBOID")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 2) = rs.Fields("ItemDescription")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 3) = rs.Fields("ItemLocation")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 4) = rs.Fields("ItemOwner")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 5) = rs.Fields("ItemStatus")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 6) = rs.Fields("ItemRemovedDate")
                        x = x + 1
                        rs.MoveNext
                        Loop
                End If
                Me.lblQTY.Caption = x
            End If
            CloseConnection
           
            Me.txtItemDescription.Text = ""
            Me.txtLocation.Text = ""
            Me.dcbStatus.Text = ""
            Me.dcbStatus.Enabled = True
            Me.dcbOwner.Text = ""
            Me.txtMoboID.Text = ""
            cmdSaveNew.Caption = "SAVE"
0
Comment
Question by:Yeavis
  • 8
  • 6
  • 2
  • +2
19 Comments
 
LVL 19

Expert Comment

by:peh803
Comment Utility
What error are you getting?  Can you provide some more specific information on this?

Offhand, the composition of your update statement appears questionable...

Try changing it to this:
strMySQL = "UPDATE tblDataChild SET " & tblDataChild.[ItemDescription] & "='" & Trim(Me.txtItemDescription.Text) & "', " & tblDataChild.[ItemMOBOID] & "='" & Trim(Me.txtMoboID.Text) & "', " & tblDataChild.[ItemLocation] & "='" & Trim(Me.txtLocation.Text) & "', " & tblDataChild.[ItemOwner]= '" & Trim(Me.dcbOwner.Text) & "', " & tblDataChild.[ItemStatus] & "='" & Trim(Me.dcbStatus.Text) & "', " & tblDataChild.[ItemRemovedDate]='" & Trim(Me.txtItemRemovedDate.Text) & "'  WHERE tblDataChild.[ID]='" & Trim(Me.txtID.Text) & "'"

Hope this helps,
peh803
0
 

Author Comment

by:Yeavis
Comment Utility
The message I am getting is: SYNTAX ERROR IN QUERY. INCOMPLETE QUERY CLAUSE.

I will try your code and see if it helps..
0
 
LVL 19

Expert Comment

by:peh803
Comment Utility
Sounds good ... If I understand correctly how you're trying to piece together your update statement, my suggestions should help.

Thanks,
peh803
0
 

Author Comment

by:Yeavis
Comment Utility
The code above errored out stating invalid use of brackets.

All I want is a query that will update the following fields, bracket is not required and it's only in there because I was trying to get it to work and thought I would give it a shot. Here are the fields I need updated:

tblDataChild:
ID (index - no updating, obviously)
ItemMoboID (Need a query with this included, and one with out. Depends on the type of inventory being input..)
ItemDescription
ItemLocation
ItemOwner
ItemStatus
ItemRemovedDate (this is option, can be left blank. How could I replace NULL values here??)

Thanks..
0
 
LVL 19

Accepted Solution

by:
peh803 earned 500 total points
Comment Utility
Try it like this:

strMySQL = "UPDATE tblDataChild SET ItemDescription='" & Trim(Me.txtItemDescription.Text) & "', ItemMOBOID='" & Trim(Me.txtMoboID.Text) & "', ItemLocation='" & Trim(Me.txtLocation.Text) & "', ItemOwner= '" & Trim(Me.dcbOwner.Text) & "', ItemStatus='" & Trim(Me.dcbStatus.Text) & "', ItemRemovedDate='" & Trim(Me.txtItemRemovedDate.Text) & "'  WHERE ID='" & Trim(Me.txtID.Text) & "'"
0
 

Author Comment

by:Yeavis
Comment Utility
Now I'm getting a "DATA TYPE MISMATCH IN QUERY EXPRESSION" message... any idea's??
0
 
LVL 19

Expert Comment

by:peh803
Comment Utility
yes, the data type mismatch indicates that you're trying to insert a string into a non-character type field.  What are the database data types for the fields you're updating?

peh803
0
 

Author Comment

by:Yeavis
Comment Utility
They are all text..  I don't modify the ID, and that is a long integer (autoincrement).
0
 

Author Comment

by:Yeavis
Comment Utility
Is there anyone else that can help me out here?? I need to get this project completed by tomorrow and I can't resolve this issue!!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Expert Comment

by:viola123
Comment Utility
hehe... try this:

strMySQL = "UPDATE tblDataChild SET ItemDescription=" + Trim(Me.txtItemDescription.Text) +" ItemMOBOID=" + Trim(Me.txtMoboID.Text)+" ItemLocation=" + Trim(Me.txtLocation.Text)+" ItemOwner="+Trim(Me.dcbOwner.Text) +" ItemStatus="+Trim(Me.dcbStatus.Text) +" ItemRemovedDate]="+Trim(Me.txtItemRemovedDate.Text)+" WHERE ID=" +Trim(Me.txtID.Text)


cheers
viola
0
 
LVL 6

Expert Comment

by:viola123
Comment Utility
one suggestion:

i suggesting check the value of strMySQL using debugger. if there is anyting wrong, i am sure you can find something abnormal in that query string variable.


cheers
viola
0
 

Author Comment

by:Yeavis
Comment Utility
I am getting a missing operator error now..  I will try to use the debugger and see if I get anything.
0
 

Author Comment

by:Yeavis
Comment Utility
Would you recommend create string variables in place of using Trim(me.txtLocation.text)?
0
 

Author Comment

by:Yeavis
Comment Utility
No matter what I do I keep getting DATA TYPE MISMATCH errors. The first field in my database is ID and it is not updateable, but when change the syntax of strMySQL to strMySQL = "UPDATE tblDataChild SET ID = '" & trim(me.txtID.text) & "'" & " WHERE ID='" & trim(me.txtID.text) & "'"   it tells me that the field ID is not updateable. This is the only time I get anything besides a DATA TYPE MISMATCH error...
0
 
LVL 22

Expert Comment

by:Helena Marková
Comment Utility
If the column ID in a table is not updateable then why are you trying to update it ?
0
 
LVL 19

Expert Comment

by:peh803
Comment Utility
Is this still a problem for you?

peh803
0
 

Expert Comment

by:huyntminh
Comment Utility
Why don't you post here your table create script. It will be easier to firgure out your bugs with the exact table structure.
0
 

Expert Comment

by:huyntminh
Comment Utility
Try this instead :

strMySQL = "UPDATE tblDataChild SET ItemDescription='" & Trim(Me.txtItemDescription.Text) & "', ItemMOBOID='" & Trim(Me.txtMoboID.Text) & "', ItemLocation='" & Trim(Me.txtLocation.Text) & "', ItemOwner= '" & Trim(Me.dcbOwner.Text) & "', ItemStatus='" & Trim(Me.dcbStatus.Text) & "', ItemRemovedDate='" & Trim(Me.txtItemRemovedDate.Text) & "'  WHERE ID=" & Trim(Me.txtID.Text)
0
 
LVL 19

Expert Comment

by:peh803
Comment Utility
@Yeavis:

This question hasn't been touched in quite some time....

Please update us on the status.  If you still need help, let us know.  Otherwise, please award points according to whoever you think deserves them, and close the question.

Thanks for your help!
peh803
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now