Hello everybody! I hope I'm in the right place to consult some programming issues.

I'm Jhun and I'm new to the datagrid of VB 6. I'm currently working on a database application in which I would like to show records from an Access DB thru the datagrid. I tried to do it with ADO's RecordSource property and is showing results. My questions are:
<1> is it possible to only show selected columns in the datagrid?
<2> Is is possible to combine columns from different tables which will be shown into the datagrid?

Thank you for your time and expertise...

~Jhun

Hi Jhun,

It should be quite easy since you have already figured out how to get data into the grid. The way to go about it is to set the RecordSource property to a query statement instead of a table name.

The RecordSources "Table1" and "SELECT * FROM Table1" will yield exactly the same results.

Now, building on this gets us
SELECT Field1, Field4, Field8 FROM Table1

will let you reduce the number of columns and

SELECT Table1.Col1, Table1.Field4, Table1.Field8, Table2.Field3, Table2.Field8
FROM Table1 INNER JOIN Table2 ON Table1.Field1 = Table2.Field1

will let you display columns (Fields) from many tables.

Now to reduce the number of rows returned you would use a WHERE clause that might look like
WHERE Table1.Field4 = <some value>
AND Table2.Field3 = <some other value>


Therefore your full query might look something like this:

SELECT Table1.Col1, Table1.Field4, Table1.Field8, Table2.Field3, Table2.Field8
FROM Table1 INNER JOIN Table2 ON Table1.Field1 = Table2.Field1
WHERE Table1.Field4 = <some value>
AND Table2.Field3 = <some other value>

As you can see this statement can be built on the fly by the code and gives you quite a bit of power over which data to display.

Hope this helps.

Happy coding

Yomet

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.