Solved

Using only part of the data in a datagrid

Posted on 2004-09-24
6
177 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:gleznov
[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
  • 2
6 Comments
 
LVL 6

Expert Comment

by:KGreg
ID: 12147053
Try this..  Does this work?

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

KGreg
0
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12167075
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.
0
 

Author Comment

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

JP
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:gleznov
ID: 12168653
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
0
 

Author Comment

by:gleznov
ID: 12169273
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
0
 
LVL 4

Accepted Solution

by:
eozz_2000 earned 125 total points
ID: 12171110
OK, this is the explanation:

1) If you are setting the dataSource and dataMember of your dataGrid at runtime then go to 4)
2)Set the dataSource of your dataGrid to the dataSet.
3)Set the dataMember of your dataGrid to the table you want to display.
4)In the TableStyles property add a new one DataGridTableStyle and set the property mappingName with the name of your table (exactly the same name that it has in dataSet).
5)In the GridColumnStyles property add as several ones as you want to show and set those mappingName property with the name of the columns mapped (exactly the same that it has in dataSet).  If you had settng the dataSource and dataMember of your dataGrid at edit time then that was all, if not then follow with the explanation.
6)In the code, set the dataSource of your dataGrid to dataSet and set the dataMember or your dataGrid to the name of the table you want to display (exactly the same name that it has in dataSet).
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 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