Solved

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

Posted on 2008-10-22
7
4,964 Views
Last Modified: 2013-11-26
Let's say I have these 2 tables

table1                                       table2
FName     LName   Status         Idstat      Desc
John        Smith         1                 1            ACTIVE
Mark        Doe            2                 2            INACTIVE

Then I aded a Datagrid into the form and bind it to the Table1 binding source and then
I tried to add a Query joining these 2 table and all field form Table1 and showing the Desc field from table2
and I got the "The schema returned by the new query differs from the base query error"
Now How do I get the Query to work on the grid, I've read that is better to build the datagrid programmatically instead of drag and drop into the form and assigned the query by code.

0
Comment
Question by:ranhell
[X]
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
  • 3
  • 3
7 Comments
 

Expert Comment

by:malibuboats
ID: 22778739
The reason why you are getting that error is because you bind the grid to table and by doing so you confined the grid to useing table1's schema.  The query now returns one more field then table1 scheme had.

Instead of binding the table to the grid via the gui try calling the query from code and binding the grid there.

Example:
var query = table1.query1().ToList();
grid1.datasource = query;
grid1.databind();
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22778779
the best way to go forward will be to bring correct data from the database and then bind that to the data grid

i will brind data like this and then bind it to the grid

select
    t1.FName,
    t1.LName,
    t2.Desc
From
    table1 t1
    Inner Join table2 t2 ON
        t1.Status = t2. IDStat
0
 
LVL 10

Author Comment

by:ranhell
ID: 22779552
Still not get it, could you be more expecific regarding to the code, I'd really appreciate it!!
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22780381
i am assuming that you are binding your data grid with a data source and that data source is a table which you have filled in by calling the sql statement or a stored procedure
if that is the case then user my query to fetch the data as it will bring in the description column too which you want to show
you can find a lots of examples on the web for binding you data grid to the datatable
0
 
LVL 10

Author Comment

by:ranhell
ID: 22780487
I was expecting a code sample of what you said, can you provide one that resembles the scenario with the above tables.
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22783459
follow this sample you can do it on your own
http://www.codeproject.com/KB/aspnet/DataGridView__GridView.aspx
0
 
LVL 10

Accepted Solution

by:
ranhell earned 0 total points
ID: 22785572
I figure it out by myself, instead of using the GUI from the datagrid
I fill it by a query programatically wich is far more robust.

Private Sub SHOWDUP()
        'DataGridView1.DataSource = Nothing
        'DataGridView1.Refresh()
        DT.Clear()
        sSql = ""
        sSql = "SELECT DUPLICADOS.ID, DUPLICADOS.FECHAIN AS FECHA,"
        sSql += " DUPLICADOS.CB AS [CODIGO DE BARRAS], DUPLICADOS.POLVORIN, DUPLICADOS.IDSTAT AS ESTATUS,"
        sSql += " PRODUCTOS.[DESC] AS PRODUCTO"
        sSql += " FROM (DUPLICADOS INNER JOIN"
        sSql += "  PRODUCTOS ON DUPLICADOS.TIPOID = PRODUCTOS.TIPOID)"
        ADOAdapter = New OleDb.OleDbDataAdapter(sSql, Con)
        ADOAdapter.Fill(DT)
        DataGridView1.DataSource = DT

        Try
        Catch Exp As Data.OleDb.OleDbException
            MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
        End Try
        Cursor.Current = Cursors.Default
    End Sub
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

622 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