The schema returned by the new query differs from the base query (C#/SQL - VS 2012)

12,133

The solution has been found, for all those wondering.

The problem is that the query returns a table which has a different number of columns that the database.

Usually in most DBMS's this is not an issue, but for some reason Visual Studio was having none of that.

The solution was this query:

SELECT employeeID, name, position, hourlyPayRate FROM employee WHERE (hourlyPayRate = (SELECT MAX(hourlyPayRate) AS MaxRate FROM employee AS TempTable))

And then trimming the unneeded from the result as you like. For me this was as simple as having a label that derived it's data only from the hourlyPayRate attribute.

Share:
12,133
user3560189
Author by

user3560189

Updated on June 04, 2022

Comments

  • user3560189
    user3560189 over 1 year

    For a homework task I have to develop a C# application to interface with a SQL Server database file (.mdf), providing a dataGridView to browse the contents, and several buttons to execute queries.

    I have been going well, found how to add queries to my table adapter, how to call them etc.

    Now I am having problems making a query that returns the maximum pay in hourlyPayRate.

    I have a database employee that contains the following attributes: employeeID, name, position, hourlyPayRate.

    My query is

    SELECT MAX(hourlyPayRate) 
    FROM employee
    

    I right click employeeTableAdapter, click "Add Query...", name it Max and put in the query. When I click okay I get the following error message:

    The schema returned by the new query differs from the base query.

    The query executes correctly in the query builder, it is only when I click "OK" to save it that I receive the error.

    Looking around SE there are no definitive answers to this question.

    Thanks, Michael.