Mail merge using datatable

4 posts, 0 answers
  1. Daniel
    Daniel avatar
    5 posts
    Member since:
    Feb 2016

    Posted 03 Mar Link to this post

    Hi

    Is it possible to use the data within a datatable as the mail merge fields within a richtecteditor? So the column headings within the datatable will show in the 'Insert merge field' drop down and the rows will be the results. 

    I have tried (which was a long shot):

    Form.RadRichTextEditor.Document.MailMergeDataSource.ItemsSource = DataSet1.Tables("table").AsEnumerable.ToList   (doesn't work)

    If its not possible could someone please suggest a best method? The data comes from a SQL view, which fills a datatable which then displays in the radgridview (which is awesome). Preferably in VB.net please.

     

    Many thanks

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 04 Mar Link to this post

    Hello Daniel,

    Thank you for writing.

    This will give you a list of rows only. To properly convert the data table you should create a business object class where you should add a property for each column. Then you can iterate the rows and create a proper data source. An example for this is available in the following discussion: c# - Convert DataTable to IEnumerable<T> - Stack Overflow

    Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Daniel
    Daniel avatar
    5 posts
    Member since:
    Feb 2016

    Posted 07 Mar Link to this post

    Thank you for your reply. This got me on to the right track. 

    I actually did it a slightly different way with the following: 

        Public Function mailmergeitems(ByRef datatable_var As DataTable)
            Dim data = datatable_var.AsEnumerable().[Select](Function(row) New With { _
             Key .Student_Family_Name = row("Student_Family_Name").ToString(), _
             Key .Student_First_Name = row("Student_First_Name").ToString() _

    })
            Shared_document_creator.RadRichTextEditor1.Document.MailMergeDataSource.ItemsSource = data

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 07 Mar Link to this post

    Hi Daniel,

    I am glad I could be of help. Let us know if you have any other questions.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top