Value of 2 dataTable in a DataSet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cortex

    Value of 2 dataTable in a DataSet

    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!

  • Cor Ligthert

    #2
    Re: Value of 2 dataTable in a DataSet

    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.ques tion_Id"), _
    ds.Tables("B"). Columns("B.ques tion_Id"))
    ds.Relations.Ad d(drlA)
    Dim dv As New DataView(ds.Tab les("A"))
    DataGrid1.DataS ource = dv
    DataGrid1.Expan d(-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








    Comment

    • cortex

      #3
      re:Value of 2 dataTable in a DataSet

      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).Ro ws '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?

      Comment

      • Cor Ligthert

        #4
        Re: re:Value of 2 dataTable in a DataSet

        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("Cort ex")
        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.Coun t - 1
        dt.Rows(i)(y) = Chr(y + 65)
        Next
        Next
        ds.Tables.Add(d t)

        Dim Cortex As New ArrayList
        For i As Integer = 0 To ds.Tables("Cort ex").Rows.Cou nt - 1
        Dim row As New System.Text.Str ingBuilder
        Cortex.Add(row)
        row.Append("<TR ><TD>")
        For y As Integer = 0 To ds.Tables("Cort ex").Columns.Co unt - 1
        row.Append(ds.T ables("Cortex") .Rows(i)(y).tos tring)
        If y <> ds.Tables("Cort ex").Columns.Co unt - 1 Then
        row.Append("</TD><TD>")
        Else
        row.Append("<TD ></TR>")
        End If
        Next
        Next
        Dim sw As New IO.StreamWriter ("C:\Cortex.htm l")
        sw.WriteLine("< HTML><HEAD></HEAD><BODY><TAB LE>")
        For i As Integer = 0 To Scorpion.Count - 1
        sw.WriteLine(Sc orpion(i).ToStr ing)
        Next
        sw.WriteLine("</TABLE></BODY></HTML>")
        sw.Flush()
        sw.Close()
        End Sub
        End Module


        Comment

        Working...