Value of 2 dataTable in a DataSet

  • Thread starter Thread starter cortex
  • Start date Start date
C

cortex

Hi all, i'm newhere and I'm french so excuse me for my bad english :(


In my dataset I have 2 Table:
-the first named questionnaire which has 4 columns: question_Id,
ennonce, format and type
-the second, named answer which as 3 columns: code, answer, and
question_Id

My data come from an XML file.

I want to display answer which are linked to a question. And this for
all question

I hope you understand me!
 
Hi Cortex,

One minute ago I did send this sample that I made just before, I changed it
a little bit here for you Tables are A and B can also be 0 and 1

Dim drlA As New DataRelation _
("AA", ds.Tables("A").Columns("A.question_Id"), _
ds.Tables("B").Columns("B.question_Id"))
ds.Relations.Add(drlA)
Dim dv As New DataView(ds.Tables("A"))
DataGrid1.DataSource = dv
DataGrid1.Expand(-1)

Do not excuse you for your English in this newsgroup, which is very
international with lot of regulars from the EU who are used at least to
understand more languages.

I hope this helps, and further question feel free to ask, however in Enlish.

Cor
 
thx for your help but:

-first: I have tryed to creta a datarelation like you but there is an
erro: "there is already a datarelation for these chiild columns"

-After: I don't want to use a datagrid: i use a loop (for each) which
build some html table

Otherwise i succed to make what i wante with this code:

iiQuestionId =
r(ds.Tables(0).Columns(0))
iiNum = iiQuestionId + 1
isEnnonce = r(ds.Tables(0).Columns(1))
isType = r(ds.Tables(0).Columns(2))



Response.write("<center><table><th>Question
" & iiNum & ": " & isEnnonce &
"</th>")
Response.write("<tr><td>")

for each r2 in ds.Tables(1).Rows 'on parcourt toutes les
lignes de la table reponse
If (r2(ds.Tables(1).Columns(3)) =
iiQuestionId) Then 'on affichque que les reponse portant le meme
Id que la reponse
if (r(ds.Tables(0).Columns(2)) =
"text") Then 'si le format de la question est text
alors on traite a part
isRepvalue = ""
isTypeFinal = "<input type='text'" &
"id='" & iiQuestionId & "' name='" &
iiQuestionId &"' size='25' runat='server'>"
Else
isRepValue = r2(ds.Tables(1).Columns(2))
isTypeFinal = "<input type='"& isType &
"'" & "id='" & iiQuestionId &
"' name='" & iiQuestionId &"'
runat='server'>"
End If
Response.write(isTypeFinal & " " &
isRepValue & "<br />")
End If
Next


Response.write("</td></tr></table></center><br
/>")
Next


But i think this isn't a good way, no?
 
Hi Cortex,

This I made once for someone who never used it.
It is for a windows application, however you get the idea and when you are
making aspx pages it should be easy enoug to translate it, when not, feel
free to ask.

I hope this helps?

Cor

Public Module main

Public Sub main()
'First the testtable
'Make a datatable with 8 columns
Dim ds As New DataSet
Dim dt As New DataTable("Cortex")
For i As Integer = 0 To 7
Dim dc As New DataColumn(Chr(i + 48))
dt.Columns.Add(dc)
Next
'And 12 rows every column filled with a letter
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(y + 65)
Next
Next
ds.Tables.Add(dt)

Dim Cortex As New ArrayList
For i As Integer = 0 To ds.Tables("Cortex").Rows.Count - 1
Dim row As New System.Text.StringBuilder
Cortex.Add(row)
row.Append("<TR><TD>")
For y As Integer = 0 To ds.Tables("Cortex").Columns.Count - 1
row.Append(ds.Tables("Cortex").Rows(i)(y).tostring)
If y <> ds.Tables("Cortex").Columns.Count - 1 Then
row.Append("</TD><TD>")
Else
row.Append("<TD></TR>")
End If
Next
Next
Dim sw As New IO.StreamWriter("C:\Cortex.html")
sw.WriteLine("<HTML><HEAD></HEAD><BODY><TABLE>")
For i As Integer = 0 To Scorpion.Count - 1
sw.WriteLine(Scorpion(i).ToString)
Next
sw.WriteLine("</TABLE></BODY></HTML>")
sw.Flush()
sw.Close()
End Sub
End Module
 
Back
Top