Dataset - newbie

G

Guest

I have a question about dataset. Please help !
I defined a dataset say ds1. I first filled ds1 with a xml file, then I filled ds1 with a database table by using dataadapter. The two tables both contain an attribute say ID. My question is how can I select some of joined columns from the two tables and bind the result to a datagrid.

For example, the first xml file -> table1 (ID, name, address, telephone)
the second database table -> table2 (ID, jobNum)
Expected result:
| ID| name| jobNum|
| 4| sam | 4120|
 
C

Cor Ligthert

Hi Alison,

Can you see it this sample fits your needs?
(You have yourself to add try and catch blocks)

I hope it helps?

Cor

\\\
Dim Sql As String = "SELECT * from A, B Where " & _
"A.n = B.n"
Dim Conn As New OleDbConnection(connString)
Dim da As New OleDbDataAdapter(Sql, Conn)
da.Fill(ds, "A")
da.Fill(ds, "B")
Conn.Close()
Dim drlA As New DataRelation _
("AA", ds.Tables("A").Columns("A.n"), _
ds.Tables("B").Columns("B.n"))
ds.Relations.Add(drlA)
Dim dv As New DataView(ds.Tables("A"))
DataGrid1.DataSource = dv
DataGrid1.Expand(-1)
////
 
G

Guest

Thanks for your reply. I forgot to say this is ASP.Net application
I tried this code. But it didn't work.
the line "DataGrid1.Expand(-1) " didn't work
 
C

Cor Ligthert

Hi Alison,

I never did this with a Webgrid, but you can try it, and than instead of
that expand.

DataGrid1.databind.

Maybe I will test it tomorrow, but please tell me your expiriences what
happened with that datagrid1.databind?.

Cor
 
G

Guest

Here is the C# code I tried. After running, the DataGrid3 didn't show on the webform at all
Schema of table A (from a xml file) is (ID, name, telephone
Schema of table B(from a sql table) is (ID, employer

dataset1.Tables [0].TableName = "A"
dataset1.Tables [1].TableName = "B"

DataColumn parentCol
DataColumn childCol

parentCol = dataset1.Tables[0].Columns["ID"]
childCol = dataset1.Tables[1].Columns["ID"]

DataRelation dataRelation1 = new DataRelation ("relation1",parentCol,childCol,false)
dataset1.Relations.Add(dataRelation1)
DataGrid3.DataSource = dataset1.Tables["A"]
 
C

Cor Ligthert

Hi Alison,

I did try it, and now I think there is no multitable possibility in a
webform datagrid, however when you find it, let me know.

Cor
 

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

Top