Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL Query Error

Posted on 2004-10-04
19
252 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
ID: 12222793
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
ID: 12222826
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
ID: 12222832
Sounds good ... If I understand correctly how you're trying to piece together your update statement, my suggestions should help.

Thanks,
peh803
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Yeavis
ID: 12222891
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
ID: 12222962
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
ID: 12223017
Now I'm getting a "DATA TYPE MISMATCH IN QUERY EXPRESSION" message... any idea's??
0
 
LVL 19

Expert Comment

by:peh803
ID: 12223032
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
ID: 12223185
They are all text..  I don't modify the ID, and that is a long integer (autoincrement).
0
 

Author Comment

by:Yeavis
ID: 12223901
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
 
LVL 6

Expert Comment

by:viola123
ID: 12224375
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
ID: 12224419
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
ID: 12224454
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
ID: 12224516
Would you recommend create string variables in place of using Trim(me.txtLocation.text)?
0
 

Author Comment

by:Yeavis
ID: 12224719
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á
ID: 12225532
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
ID: 12226186
Is this still a problem for you?

peh803
0
 

Expert Comment

by:huyntminh
ID: 12246707
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
ID: 12246734
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
ID: 12361243
@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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

856 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