populating a DataTable in a DataSet

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

    populating a DataTable in a DataSet

    Hi,

    I have done following: Add new item - Dataset, then add DataTable, and
    add a few fields (VS2005) because this seems the only way to let a
    Crystalreport recognize a datatable in the project.

    Now the problem, should be simple but I cannot find it. How can I
    populate the dataTable in code ? I don't need a connection to a
    database and so.

    --
    rgds, Wilfried [MapPoint MVP]

  • Dave Sexton

    #2
    Re: populating a DataTable in a DataSet

    Hi Wilfried,

    Here's a simplified example:

    "How To: Fill a DataSet with Data":


    --
    Dave Sexton

    "Wilfried Mestdagh" <wilfried@mestd agh.bizwrote in message
    news:OGli6MCAHH A.4292@TK2MSFTN GP02.phx.gbl...
    Hi,
    >
    I have done following: Add new item - Dataset, then add DataTable, and add a
    few fields (VS2005) because this seems the only way to let a Crystalreport
    recognize a datatable in the project.
    >
    Now the problem, should be simple but I cannot find it. How can I populate
    the dataTable in code ? I don't need a connection to a database and so.
    >
    --
    rgds, Wilfried [MapPoint MVP]
    http://www.mestdagh.biz

    Comment

    • Dave Sexton

      #3
      Re: populating a DataTable in a DataSet

      Hi Wilfried,

      I'm sorry, I just realized you wrote "don't" need a connection to a database.

      In that case, here's a simple example. Assuming that you have a strong-typed
      DataSet named, "PeopleData " that contains a single DataTable named, "People",
      which only contains a single column named, "Name" of type System.String, you
      could do the following:

      PeopleData data = new PeopleData();
      data.People.Add PeopleRow("Joe" );
      data.People.Add PeopleRow("Fred ");
      data.AcceptChan ges();

      HTH

      --
      Dave Sexton

      "Wilfried Mestdagh" <wilfried@mestd agh.bizwrote in message
      news:OGli6MCAHH A.4292@TK2MSFTN GP02.phx.gbl...
      Hi,
      >
      I have done following: Add new item - Dataset, then add DataTable, and add a
      few fields (VS2005) because this seems the only way to let a Crystalreport
      recognize a datatable in the project.
      >
      Now the problem, should be simple but I cannot find it. How can I populate
      the dataTable in code ? I don't need a connection to a database and so.
      >
      --
      rgds, Wilfried [MapPoint MVP]
      http://www.mestdagh.biz

      Comment

      • Brendon Bezuidenhout

        #4
        Re: populating a DataTable in a DataSet

        Heya Wilfried,

        Daft question - but re your Crystal Report - Are you attempting to
        dynamically alter the design and such of the CrystalReport proper? If so a
        heads up of a headache that I had to find out the hard way - You can't with
        the API and CrystalReports namespace that is shipped with VS2005...

        If not ignore me :)

        Brendon




        "Wilfried Mestdagh" <wilfried@mestd agh.bizwrote in message
        news:OGli6MCAHH A.4292@TK2MSFTN GP02.phx.gbl...
        Hi,
        >
        I have done following: Add new item - Dataset, then add DataTable, and add
        a few fields (VS2005) because this seems the only way to let a
        Crystalreport recognize a datatable in the project.
        >
        Now the problem, should be simple but I cannot find it. How can I populate
        the dataTable in code ? I don't need a connection to a database and so.
        >
        --
        rgds, Wilfried [MapPoint MVP]
        http://www.mestdagh.biz

        Comment

        • Wilfried Mestdagh

          #5
          Re: populating a DataTable in a DataSet

          Hi Dave,

          Thanks I give that a try :)

          --
          rgds, Wilfried [MapPoint MVP]

          Comment

          • Wilfried Mestdagh

            #6
            Re: populating a DataTable in a DataSet

            Hy Brendon,

            Yes and no, but I just discovered ReportViewer witch seems very much
            simpler to work with. Also it understand Object Data Sources, which I
            think this is improvement. Now I have to learn these things too :)

            --
            rgds, Wilfried [MapPoint MVP]


            Brendon Bezuidenhout wrote:
            Heya Wilfried,
            >
            Daft question - but re your Crystal Report - Are you attempting to
            dynamically alter the design and such of the CrystalReport proper? If so
            a heads up of a headache that I had to find out the hard way - You can't
            with the API and CrystalReports namespace that is shipped with VS2005...
            >
            If not ignore me :)
            >
            Brendon
            >
            >
            >
            >
            "Wilfried Mestdagh" <wilfried@mestd agh.bizwrote in message
            news:OGli6MCAHH A.4292@TK2MSFTN GP02.phx.gbl...
            >Hi,
            >>
            >I have done following: Add new item - Dataset, then add DataTable, and
            >add a few fields (VS2005) because this seems the only way to let a
            >Crystalrepor t recognize a datatable in the project.
            >>
            >Now the problem, should be simple but I cannot find it. How can I
            >populate the dataTable in code ? I don't need a connection to a
            >database and so.
            >>
            >--
            >rgds, Wilfried [MapPoint MVP]
            >http://www.mestdagh.biz
            >

            Comment

            • Peter Bromberg [C# MVP]

              #7
              RE: populating a DataTable in a DataSet

              Here is an alternate way (not using strongly typed):

              DataSet ds = new DataSet();
              DataTable dt = new DataTable();
              dt.Columns.Add( "TEST");
              DataRow row ;
              for(int i = 0;i<3;i++)
              {
              row=dt.NewRow() ;
              row["TEST"] ="Howdy " +i.ToString();
              dt.Rows.Add(row );
              }
              ds.Tables.Add(d t);

              Done! Cheers,

              Peter



              --
              Co-founder, Eggheadcafe.com developer portal:

              UnBlog:





              "Wilfried Mestdagh" wrote:
              Hi,
              >
              I have done following: Add new item - Dataset, then add DataTable, and
              add a few fields (VS2005) because this seems the only way to let a
              Crystalreport recognize a datatable in the project.
              >
              Now the problem, should be simple but I cannot find it. How can I
              populate the dataTable in code ? I don't need a connection to a
              database and so.
              >
              --
              rgds, Wilfried [MapPoint MVP]

              >

              Comment

              Working...