Link to home
Start Free TrialLog in
Avatar of gleznov
gleznov

asked on

Using only part of the data in a datagrid

Hi,

     I'm filling a dataset with an entire table (because my code encounters errors if I don't).  Then I want only 4 columns of that table to appear in a datagrid.  Here's where I'm messed up:

I use a dataadapter to define a select * on my table, supplies_trans.  Then I generate a dataset from that.

I use this code to try and start up:

 Dim DRGrid As New SqlClient.SqlDataAdapter("select * from supplies_trans order by trans_date", SqlConnection1)
        DRGrid.Fill(DataSet_Supplies1, "Supplies_Trans")

        DBGrid1.DataSource = DataSet_Supplies1
        DBGrid1.DataMember = "Supplies_Trans"

The DRGrid.Fill crashes me in these cases:

1) if the statement above it has select item, item alias, item etc (so I have to use select *)

2) if I've created a dataadapter using such a select statement other than select *

So I don't know if I can narrow it down somehow before connecting datasource/member to it.  Maybe make another dataset and pull only the info I want (but I don't know the commands for this (or rather methods/etc)) or to be able to somehow say DBGrid1.only show these columns

JP
Avatar of KGreg
KGreg

Try this..  Does this work?

"SELECT supplies_trans.trans_date, supplies_trans.item FROM supplies_trans ORDER BY supplies_trans.trans_date"

KGreg
You can add (in editon time) a new TableStyle in the TableSyleCollection of your DataGrid and map it to the name of you table in DataSet, and then add as new DataGridColumnStyles as you need and map them to the columns (names) you want to display.
Avatar of gleznov

ASKER

Can you be more specific?  How exactly do I use that?  It sounds like what I'm looking for.

JP
Avatar of gleznov

ASKER

I created a tablestyle with the columns I want using the GUI - the grid is mapped to the table, then I made tablestyles.  Is this wrong?  I still get the full table output (all columns w/ their original names)

JP
Avatar of gleznov

ASKER

I figured it out - I don't know what was wrong with my original but when I tweaked the select statements around and redid stuff, it worked fine.  I think maybe some minor non-matchup in the select statement for the dataadapter and the one to fill the control were causing my main problems.

JP
ASKER CERTIFIED SOLUTION
Avatar of eozz_2000
eozz_2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial