Data Relation

P

Peter W Johnson

Hi Guys,



I am trying to display a datagrid containing two related datasets. I have
filled and related them on MemberID with the following code:-



Dim myconnection As Odbc.OdbcConnection

Dim myda As Odbc.OdbcDataAdapter

Dim mysql As String

myconnection = New Odbc.OdbcConnection("DSN=database")

'get data from members table

mysql = "Select * from tblMembers"

myda = New Odbc.OdbcDataAdapter(mysql, myconnection)

myda.Fill(ds, "Members")

'get data from Category table

mysql = "Select * from tblMemberCategory"

myda = New Odbc.OdbcDataAdapter(mysql, myconnection)

myda.Fill(ds, "Category")

'added the data relation

ds.Relations.Add("AllMembers", ds.Tables("Members").Columns("MemberID"),
ds.Tables("Category").Columns("MemberID"))

'Set the datagrid source and populate the Datagrid

DataGridMember.DataSource = ds.Tables("AllMembers")

DataGridMember.TableStyles.Clear()

DataGridMember.Visible = True

'Close the Data connection when complete

myconnection.Close()



All I end up with is an empty datagrid. Any ideas why?



Cheers



Peter.
 
C

Cor Ligthert

Peter,
I am trying to display a datagrid containing two related datasets. I have
filled and related them on MemberID with the following code:-

You can not use a relation between two datasets, therefore is exactly the
dataset. It can holds relations between tables *in* a dataset.

I hope this helps,

Cor
 
P

Peter W Johnson

Cor,

Isn't that what I have? I have one Dataset call ds with two tables, Members
and Category. Shouldn't Data Relation hold the relation between those two
tables in the same dataset?

Cheers

Peter.
 
C

Cor Ligthert

Peter,

Isn't that what I have? I have one Dataset call ds with two tables,
Members and Category. Shouldn't Data Relation hold the relation between
those two tables in the same dataset?
When I see in a text something that can be the error, than I answer that. I
think than non of us start examining if there are more errors. Therefore
please give good information.

In the way you ask your question it is in my opinion not so clever to get
help. Maybe there are more misleading things that we should suppose to know.

By instance a special reason that you clear the grid style and set the
dataset to the table, or that you see a + as first row of your grid, however
no data. etc etc.

Cor
 
P

Peter W Johnson

Cor,

Thanks for the reply.

I have tried a number of ways to display the data but am not successful.

if I change

DataGridMember.DataSource = ds.Tables("AllMembers")

to

DataGridMember.DataSource = ds.Tables("Members")

I can see the datagrid with the + sign in the first row. But I would like to
display the related fields in the same datagrid (with the additional
columns). Maybe this is not possible.

Thanks for your help.

Peter.
 
C

Cor Ligthert

Peter

Did you try this one already?

\\\
DataGridMember.DataSource = ds
DataGrid1.Expand(-1)
///

Cor
 
P

Peter W Johnson

Cor,

I'll give it a go. I eventually linked the two tables together in an Access
query and displayed that. Not the most elegant way but it worked.

Thanks for your help.

Peter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

UpdateCommand 5
Processing speed 3
Datagrid record count 4
Data Binding with CSV Files 2
need help with array in VB 4
SQL Join and ASP.NET dataset - newbie 2
Doubt creating a class/function? 5
CSV Confusion... 2

Top