Solved

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

Posted on 2008-10-22
7
4,893 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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