Solved

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

Posted on 2008-10-22
7
4,804 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
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FInd Image Control Gridview 3 22
JSON Deserialize issue 6 26
Groupbox Control ? 2 19
How can I do Unit Testing with Session ? 1 13
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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