none
Query to select values from 2 combo boxes Microsoft Access database using C# RRS feed

  • Question

  • Hi,

    This is the query that has to select Field Name, Oil Recoverable PP MMbbl...from combobox1 (where all the tables in a database are listed) and depending on what (table_name) user clicks on, the combobox2 is loaded with related column_list (basin name) from that particular user selected table  and when user selects a particular basin name, then that particular basin name has to be checked with all the related basin names in the database and for every duplicated value of that particular user selected basin name (from combo box2) it has to return field name. oil recoverable.... This query is written to reflect these requirements but unfortunately it gives an error which is listed below the query:

    (Select \"Field Name\", \"Oil Recoverable PP MMbbl\", \"Gas Recoverable PP MMscf\", \"Cond Recoverable PP MMbbl\" from \""

    + comboBox1.SelectedItem.ToString() + "\" Where " + comboBox2.SelectedItem.ToString().Equals("Select \"Basin Name\" from \"" + comboBox1.SelectedItem + "\"")

    Error:Syntax error in union query.

    Please help me with this!!

    Thanks and Regards
    /Dani

    Thursday, August 13, 2009 8:33 AM

Answers

  • Hi Dani,

    Generally we use the brackets to enclose the column and table names as Paul suggested.  But I think the double quotes are also fine here. 

    I also agree with Val and Paul that The WHERE part may cause some issues.  comboBox2.SelectedItem.ToString.Equals(“…”) returns a Boolean value (TRUE or FALSE).  I don’t think the SQL recognize False or True in the query. 

     

    Have a nice day!

     

    Best Regards,
    Lingzhi

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 18, 2009 3:54 PM
    Moderator
  • I do not think you could use FALSE as word in WHERE clause. You need to have an expression like 1=0 that always produces false result, but cannot use FALSE
    Val Mazur (MVP) http://www.xporttools.net
    Wednesday, August 19, 2009 10:43 AM
    Moderator

All replies

  • This error is related to the actual SQL syntax and I would recommend to print  the actual SQL stastement that formed after all the concatenations are done and post it here. I believe the WHERE part of the SQL statement might cause some issues, but it is hard to say what is there untill we could see the actual SQL statement
    Val Mazur (MVP) http://www.xporttools.net
    Thursday, August 13, 2009 11:11 AM
    Moderator
  • Select "Field Name", "Oil Recoverable PP MMbbl", "Gas Recoverable PP MMscf", "Cond Recoverable PP MMbbl"  from "NS_Field db" Where False

    This is the sql statement that is the result after all the concatenations are done!!

    /Sree
    Thursday, August 13, 2009 12:56 PM
  • I wouldn't use double quotes to enclose column names - use brackets instead. Not sure if I understand the purpose of your WHERE clause.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, August 13, 2009 4:15 PM
  • Hi Dani,

    Generally we use the brackets to enclose the column and table names as Paul suggested.  But I think the double quotes are also fine here. 

    I also agree with Val and Paul that The WHERE part may cause some issues.  comboBox2.SelectedItem.ToString.Equals(“…”) returns a Boolean value (TRUE or FALSE).  I don’t think the SQL recognize False or True in the query. 

     

    Have a nice day!

     

    Best Regards,
    Lingzhi

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 18, 2009 3:54 PM
    Moderator
  • I do not think you could use FALSE as word in WHERE clause. You need to have an expression like 1=0 that always produces false result, but cannot use FALSE
    Val Mazur (MVP) http://www.xporttools.net
    Wednesday, August 19, 2009 10:43 AM
    Moderator