Retrieving the data from SQL Server and displaying it in FlowDocument

I did this small demonstration in one of my presentations and thought I’ll post this very simple code snippet. I’m reading the data from Address table in AdventureWorks database and displaying it in a flow document here goes the code


public partial class Window1 : Window


        public Window1()






        public void CreateFlowDocument()


            SqlConnection con = new SqlConnection();

            con.ConnectionString = "Data Source=SQLDB;Initial Catalog=AdventureWorks;Integrated Security=True";


            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "Select  AddressLine1,City  from Person.Address";

            cmd.Connection = con;

            SqlDataReader rdr=cmd.ExecuteReader()   ;

            StringBuilder strbldr = new StringBuilder();

            while (rdr.Read())


                strbldr.AppendLine(rdr[0].ToString() + rdr[1].ToString()+"nICE"); ;




            Paragraph myParagraph = new Paragraph();

            myParagraph.Inlines.Add(new Bold(new Run("Some bold text in the paragraph.")));

            myParagraph.Inlines.Add(new Run(strbldr.ToString() ));

            FlowDocument myFlowDocument = new FlowDocument();


            SolidColorBrush objBrush=new SolidColorBrush();

            objBrush.Color =Colors.Blue ;

            myFlowDocument.Background = objBrush;

            FlowDocumentReader myFlowDocumentReader = new FlowDocumentReader();

            myFlowDocumentReader.Document = myFlowDocument;

            this.Content = myFlowDocumentReader;






Comments (0)

Skip to main content