Solved

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

Posted on 2008-10-22
7
4,636 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now