PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

How to bind DataGrid to SQL query ?

 
 
Dmitry Sazonov
Guest
Posts: n/a
 
      18th Jul 2003
I have 2 tables:
Customers (
Cust_id int,
Cust_name text,
Type_id int )
Customer_Types (
Type_id int,
Type_name text )

I have loaded them into DataSet. When I can bind DataGrid as:

DataView view = new DataView ( ds.Tables["Customers"] );
dataGrid1.DataSource = view;

But I need to bind query to DataGrid (or to ListView). SQL like that:
"SELECT Cust_id, Cust_name, Type_name FROM Customers
INNER JOIN Customer_Types ON Customer_Types.Type_id = Customers.Type_id"

I can not create DataView on SQL query. I can not bind Grid to anything else
than DataView? I can not bind ListView to anything.

Please, help. Sorry for dumb question.


 
Reply With Quote
 
 
 
 
Ravikanth[MVP]
Guest
Posts: n/a
 
      18th Jul 2003
Hi

Could you please breifly tell what is the error you are
getting.

Ravikanth


>-----Original Message-----
>I have 2 tables:
> Customers (
> Cust_id int,
> Cust_name text,
> Type_id int )
> Customer_Types (
> Type_id int,
> Type_name text )
>
> I have loaded them into DataSet. When I can bind

DataGrid as:
>
> DataView view = new DataView ( ds.Tables

["Customers"] );
> dataGrid1.DataSource = view;
>
> But I need to bind query to DataGrid (or to

ListView). SQL like that:
>"SELECT Cust_id, Cust_name, Type_name FROM Customers
>INNER JOIN Customer_Types ON Customer_Types.Type_id =

Customers.Type_id"
>
>I can not create DataView on SQL query. I can not bind

Grid to anything else
>than DataView? I can not bind ListView to anything.
>
>Please, help. Sorry for dumb question.
>
>
>.
>

 
Reply With Quote
 
Ravikanth[MVP]
Guest
Posts: n/a
 
      18th Jul 2003
Hi

Could you please breifly tell what is the error you are
getting.

Ravikanth


>-----Original Message-----
>I have 2 tables:
> Customers (
> Cust_id int,
> Cust_name text,
> Type_id int )
> Customer_Types (
> Type_id int,
> Type_name text )
>
> I have loaded them into DataSet. When I can bind

DataGrid as:
>
> DataView view = new DataView ( ds.Tables

["Customers"] );
> dataGrid1.DataSource = view;
>
> But I need to bind query to DataGrid (or to

ListView). SQL like that:
>"SELECT Cust_id, Cust_name, Type_name FROM Customers
>INNER JOIN Customer_Types ON Customer_Types.Type_id =

Customers.Type_id"
>
>I can not create DataView on SQL query. I can not bind

Grid to anything else
>than DataView? I can not bind ListView to anything.
>
>Please, help. Sorry for dumb question.
>
>
>.
>

 
Reply With Quote
 
Kathleen Dollard
Guest
Posts: n/a
 
      19th Jul 2003
Dmitry,

You are describing two problems... restricting columns and a join. In SQL
you can solve these together, in .NET you can't. One solution _IF you aren't
updating_ is to get an extra copy of your data from SQL Server - thus three
resultsets - Customers, Customer_Types, and joined table. You can actually
do this if you are updating, but all updates against a join will take
special code.

Restricting columns requires a GridTableStyles and GridColumnStyles. Bind
via the property pages and check out the generated code.

The join is more problematic. In this case, your join is for a lookup value.
I don't join for lookup values in Windows.Forms, except under duress (large
lookup lists). Instead I bind a combo box and let Windows.Forms do the work.
In the case of the @#%%^#^$^ datagrid, this requires non-trivial effort.
www.gotdotnet.com has examples of adding a cmbo box to a data grid. This is
the answer if your user should be able to change the customer type. You can
use similer techniques to capture the paint event of the cell and print out
your type_id, even if you don't want a combo.

Alternatively, you can create a new DataSet and copy the columns in the way
you want. This is slow, but will probably cause no discernable delay on
WIndows.Forms (I'd hesitate to use this on an app server). In this case you
are basically doing a manual join.

Or you could retrieve the data the way you want from your backend.

I don't know whether we should ever have a client side join or not. SQL
Server (and MSDE which is the same thing) offers a tremendous engine for
optimizing queries. I don'twant the overhead of such a sophisticated engine
client side. Nor am I excited about a non-performant solution that looks
just like a highly efficient back end tool. Stil, the current answers are a
pain.

--
Kathleen (MVP-VB)



"Dmitry Sazonov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have 2 tables:
> Customers (
> Cust_id int,
> Cust_name text,
> Type_id int )
> Customer_Types (
> Type_id int,
> Type_name text )
>
> I have loaded them into DataSet. When I can bind DataGrid as:
>
> DataView view = new DataView ( ds.Tables["Customers"] );
> dataGrid1.DataSource = view;
>
> But I need to bind query to DataGrid (or to ListView). SQL like that:
> "SELECT Cust_id, Cust_name, Type_name FROM Customers
> INNER JOIN Customer_Types ON Customer_Types.Type_id = Customers.Type_id"
>
> I can not create DataView on SQL query. I can not bind Grid to anything

else
> than DataView? I can not bind ListView to anything.
>
> Please, help. Sorry for dumb question.
>
>



 
Reply With Quote
 
Dmitry Sazonov
Guest
Posts: n/a
 
      21st Jul 2003
thank you very much. I will look at these examples and I hope it will help.
Anyway, I feel what Microsoft did a huge job with ADO.NET and Windows forms,
but they did nothing for this very important issue: JOINs on the client
side...

"Kathleen Dollard" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dmitry,
>
> You are describing two problems... restricting columns and a join. In SQL
> you can solve these together, in .NET you can't. One solution _IF you

aren't
> updating_ is to get an extra copy of your data from SQL Server - thus

three
> resultsets - Customers, Customer_Types, and joined table. You can actually
> do this if you are updating, but all updates against a join will take
> special code.
>
> Restricting columns requires a GridTableStyles and GridColumnStyles. Bind
> via the property pages and check out the generated code.
>
> The join is more problematic. In this case, your join is for a lookup

value.
> I don't join for lookup values in Windows.Forms, except under duress

(large
> lookup lists). Instead I bind a combo box and let Windows.Forms do the

work.
> In the case of the @#%%^#^$^ datagrid, this requires non-trivial effort.
> www.gotdotnet.com has examples of adding a cmbo box to a data grid. This

is
> the answer if your user should be able to change the customer type. You

can
> use similer techniques to capture the paint event of the cell and print

out
> your type_id, even if you don't want a combo.
>
> Alternatively, you can create a new DataSet and copy the columns in the

way
> you want. This is slow, but will probably cause no discernable delay on
> WIndows.Forms (I'd hesitate to use this on an app server). In this case

you
> are basically doing a manual join.
>
> Or you could retrieve the data the way you want from your backend.
>
> I don't know whether we should ever have a client side join or not. SQL
> Server (and MSDE which is the same thing) offers a tremendous engine for
> optimizing queries. I don'twant the overhead of such a sophisticated

engine
> client side. Nor am I excited about a non-performant solution that looks
> just like a highly efficient back end tool. Stil, the current answers are

a
> pain.
>
> --
> Kathleen (MVP-VB)
>
>
>
> "Dmitry Sazonov" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I have 2 tables:
> > Customers (
> > Cust_id int,
> > Cust_name text,
> > Type_id int )
> > Customer_Types (
> > Type_id int,
> > Type_name text )
> >
> > I have loaded them into DataSet. When I can bind DataGrid as:
> >
> > DataView view = new DataView ( ds.Tables["Customers"] );
> > dataGrid1.DataSource = view;
> >
> > But I need to bind query to DataGrid (or to ListView). SQL like

that:
> > "SELECT Cust_id, Cust_name, Type_name FROM Customers
> > INNER JOIN Customer_Types ON Customer_Types.Type_id = Customers.Type_id"
> >
> > I can not create DataView on SQL query. I can not bind Grid to anything

> else
> > than DataView? I can not bind ListView to anything.
> >
> > Please, help. Sorry for dumb question.
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bind datagrid to SQL query using a CURSOR Niclas Microsoft ASP .NET 1 24th Jun 2006 09:56 AM
How do i bind such a class to datagrid? Julia Microsoft C# .NET 4 24th May 2005 03:49 PM
DataGrid Bind to DataSet, then Bind to DaTaview, GOT ERROR...PLS HELP A_PK Microsoft Dot NET Compact Framework 16 13th Apr 2005 04:27 AM
DataGrid Bind to DataSet, then Bind to DaTaview, GOT ERROR...PLS HELP A_PK Microsoft VB .NET 17 13th Apr 2005 04:27 AM
DataGrid bind chora Microsoft Dot NET Compact Framework 3 27th Nov 2004 06:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 AM.