{"id":929,"date":"2008-07-08T00:36:22","date_gmt":"2008-07-08T07:36:22","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/books\/?p=929"},"modified":"2008-07-08T00:36:22","modified_gmt":"2008-07-08T07:36:22","slug":"2011-demonstrate-adding-a-database-field","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/2011-demonstrate-adding-a-database-field\/","title":{"rendered":"20.11 Demonstrate Adding a Database Field"},"content":{"rendered":"<h2>Demonstrate Adding a Database Field to the Report<\/h2>\n<p>Finally, we get to see how everything works by demonstating the code which creates all the necessary objects and calls the AddDatabaseField() method to put the object on the report. This code uses the Form_Load() event so that report is built immediately when the form opens. Of course, you can copy and paste this code into the appropriate method for your application.<\/p>\n<p>         <b>Listing 20-9. Demonstrating adding a database field to the report.<\/b><br \/>\n         <b>[VB.NET]<\/b><br \/>\n         <code>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<\/code><br \/>\n         <code>'Declare both the reporting objects<\/code><br \/>\n         <code>Dim myReportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument = Nothing<\/code><br \/>\n         <code>Dim rcd As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument = Nothing<\/code><br \/>\n         <code>OpenReportClientDocument(\"C:\\CrystalReport1.rpt\", myReportDocument, rcd)<\/code><br \/>\n         <code>'Create the fontcolor object<\/code><br \/>\n         <code>Dim FontColor As CrystalDecisions.ReportAppServer.ReportDefModel.FontColor<\/code><br \/>\n         <code>FontColor = NewFontColor(10, \"Times New Roman\", True, False)<\/code><br \/>\n         <code>'Get a reference to the section where the object will be placed<\/code><br \/>\n         <code>Dim mySection As CrystalDecisions.ReportAppServer.ReportDefModel.Section<\/code><br \/>\n         <code>mySection = GetSection(\"DetailArea1\", 0, rcd)<\/code><br \/>\n         <code>'Add the object to the report<\/code><br \/>\n         <code>AddDatabaseField(\"Orders\", \"Ship Via\", 0, 1000, 221, 1000, mySection, FontColor, rcd)<\/code><br \/>\n         <code>CrystalReportViewer1.ReportSource = myReportDocument<\/code><br \/>\n         <code>End Sub<\/code><br \/>\n         <b>[C#]<\/b><br \/>\n         <code>private void Form1_Load(object sender, EventArgs e)<\/code><br \/>\n         <code>{<\/code><br \/>\n         <code>\/\/ Declare both of the reporting objects<\/code><br \/>\n         <code>CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument = null;<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rcd = null;<\/code><br \/>\n         <code>\/\/Load the report into memory<\/code><br \/>\n         <code>OpenReportClientDocument(@\"C:\\CrystalReport1.rpt\", ref myReportDocument, ref rcd);<\/code><br \/>\n         <code>\/\/Create the fontcolor object<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ReportDefModel.FontColor FontColor;<\/code><br \/>\n         <code>FontColor = NewFontColor(10, \"Times New Roman\", true, false);<\/code><br \/>\n         <code>\/\/Get a reference to the section where the report object will be placed<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ReportDefModel.Section mySection;<\/code><br \/>\n         <code>mySection = GetSection(\"DetailArea1\", 0, rcd);<\/code><br \/>\n         <code>\/\/Create the report object and place it on the report<\/code><br \/>\n         <code>AddDatabaseField(\"Orders\", \"Ship Via\", 0, 1000, 221, 1000, mySection, FontColor, rcd);<\/code><br \/>\n         <code>\/\/Preview the report in the viewer<\/code><br \/>\n         <code>crystalReportViewer1.ReportSource = myReportDocument;<\/code><br \/>\n         <code>}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Demonstrate Adding a Database Field to the Report Finally, we get to see how everything works by demonstating the code which creates all the necessary objects and calls the AddDatabaseField() method to put the object on the report. This code uses the Form_Load() event so that report is built immediately when the form opens. Of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,40],"tags":[],"class_list":["post-929","post","type-post","status-publish","format-standard","hentry","category-chapter-20-dynamic-report-modification","category-crystal-reportsnet-2008","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=929"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/929\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=929"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}