2 Replies Latest reply on May 5, 2016 4:02 PM by ryanfrrll4@gmail.com

    ODBC .NET - Only SELECT * Works

    ryanfrrll4@gmail.com

      Hello,

       

      I am testing out ODBC using FileMaker Pro 11 locally. I created a test database with simple 3 simple fields (First, Last, Age). I am using .NET. My database connection works just fine, but when I try to select individual fields rather than all fields I get an exception on the bolded line:

       

      using (OdbcConnection fmpConnection = new OdbcConnection(connectionString))

                 {

                      fmpConnection.Open();

                      OdbcCommand fmpQuery = new OdbcCommand(queryString, fmpConnection);

                     OdbcDataReader dr = fmpQuery.ExecuteReader();

                      while (dr.Read())

                      {

                          System.Diagnostics.Debug.WriteLine(dr.GetName(0).ToString());

                      }

                  }

       

      The exception tells me there is an error in the syntax of my query. I am probably missing something terribly obvious.

       

      The query string that hits the exception is:

      string queryString = "SELECT First, Last FROM Test";

       

      The query string that works is:

      string queryString = "SELECT * FROM Test";

       

      I returned the field names to determine if ... for whatever reason ... they were not called what I named them in the Layout. But they are.

       

      Any ideas? Has anyone else experienced this?

       

      Thank you so much,

       

      EDIT: As I was writing this I figured it out. I had to change my query string to:

       

      string queryString = "SELECT \"First\", \"Last\", \"Age\" FROM Test";

       

      Hopefully someone benefits from this.

       

      R