none
Simple where clause error RRS feed

  • Question

  • query = @"select * from customerdetails where group = " ;
    query += @" ' " + cmbselect.Text.Trim() + @" '";

    string constr;
    constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Smsdatabase.mdb;Jet OLEDBBig Smileatabase Password=dbpass";
    OleDbConnection aConnection = new OleDbConnection(constr);
    aConnection.Open();
    OleDbCommand aCommand = new OleDbCommand(query, aConnection);
    OleDbDataReader aReader = aCommand.ExecuteReader();
    checkedListBox1.Items.Clear();
    while (aReader.Read())
    checkedListBox1.Items.Add(aReader[0]);


    Guys the above is the piece of the code i am running through c#.
    I dont know why the hell it's giving Syntax error in where clause,

    Here is the screenshot of the table
    Just 18 kb.


    PLEASE SOLVE MY PROBLEM PLEASE !

    http://img263.imageshack.us/my.php?image=databasessqf5.gif
    Saturday, February 9, 2008 1:58 PM

Answers

All replies

  • This example may help you

    sorry it's in vb, i don't use c#

     

    Private Sub read_TableInfo_records()

     

            TableInfo_string = "SELECT ID FROM TableInfo WHERE ID = @ID_value"

            TableInfo_command = New OleDb.OleDbCommand(TableInfo_string, MYDB_connection)

            TableInfo_command.Parameters.Add(New OleDb.OleDbParameter("@ID_value", OleDb.OleDbType.Integer, 0)).Value = cmbselect.Text.Trim() 

     

            If TableInfo_command.Connection.State = ConnectionState.Closed Then

                TableInfo_command.Connection.Open()

            End If

     

            TableInfo_data_reader = TableInfo_command.ExecuteReader()

            If TableInfo_data_reader.HasRows Then

                'Msgbox("Records Found")

                While TableInfo_data_reader.Read

                    If Not TypeOf TableInfo_data_reader("ID") Is DBNull Then

                        checkedListBox1.Items.Add(CStr(TableInfo_data_reader("ID")))

                    End If

     

                End While

            Else

                MsgBox("No records found")

            End If

            TableInfo_data_reader.Close()

            TableInfo_command.Connection.Close()

     

        End Sub

     

    Saturday, February 9, 2008 2:40 PM
  • Friend
    The group field ia simple text field of MS Access.
    I dont know why such a simple query is causing this problem !

    I am supposed to find all the records in customerdetails where group = cmbselect.Text.


    HELP ME GUYS !
    Saturday, February 9, 2008 4:19 PM
  • In the last year that i have been looking at database queries, i don't think i have ever seen one with all those @ signs.

     

    I am not saying that is the problems but something just doesn't look right.

    i am not sure what all those @ signs do for the query if you don't use a parameter.

     

     

     

    query = @"select * from customerdetails where group = " ;
    query += @" ' " + cmbselect.Text.Trim() + @" '";

    string constr;
    constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Smsdatabase.mdb;Jet OLEDBatabase Password=dbpass";

    Saturday, February 9, 2008 4:36 PM
  • Verbatim string literals begin with @" and end with the matching quote. They do not have escape sequences.

    So the statement:

    test=@"c:\tEST\TEST.doc";

    is same as:

    test="c:\\tEST\\TEST.doc";


    WHoa !
    i am supposed to get answer here or explaining things to people !

    Anyways now u know .Can u spot the problem now , or anyone here ?
    Saturday, February 9, 2008 6:01 PM
  • ROFL            LMAO !  

    Group is a fu*king  keyword of sql !
    Saturday, February 9, 2008 6:44 PM