{"id":928,"date":"2008-07-08T00:36:22","date_gmt":"2008-07-08T07:36:22","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/books\/?p=928"},"modified":"2008-07-08T00:36:22","modified_gmt":"2008-07-08T07:36:22","slug":"2010-add-the-database-field-to-the-report","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/2010-add-the-database-field-to-the-report\/","title":{"rendered":"20.10 Add the Database Field to the Report"},"content":{"rendered":"<h2>Add Database Field to the Report<\/h2>\n<p>The code to add the database field to the report creates a new field object and uses the objects created in the previous code listings to set its properties. To try and keep the method as simple as possible, the FontClass object and Section object must be created prior to calling this method. That code will be shown in the next section.<\/p>\n<p>The arguments in this method are pretty self-explanatory. You pass it the table name and field name of the database field you want to put on the report. Next you give it the object coordinates and dimensions. After that are the Section and FontColor objects.<\/p>\n<p>         <b>Listing 20-8. Adding the database field to the report.<\/b><br \/>\n         <b>[VB.NET]<\/b><br \/>\n         <code>Public Shared Sub AddDatabaseField(ByVal TableName As String, ByVal FieldName As String, ByVal Top As Integer, ByVal Left As Integer, ByVal Height As Integer, ByVal Width As Integer, ByVal Section As CrystalDecisions.ReportAppServer.ReportDefModel.Section, ByVal FontColor As CrystalDecisions.ReportAppServer.ReportDefModel.FontColor, ByVal rcd As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument)<\/code><br \/>\n         <code>'Find the data source field to place to add to the report<\/code><br \/>\n         <code>Dim myField As CrystalDecisions.ReportAppServer.DataDefModel.Field<\/code><br \/>\n         <code>myField = GetField(TableName, FieldName, rcd)<\/code><br \/>\n         <code>'Create the report object that will be added to the report<\/code><br \/>\n         <code>Dim myFieldObject As CrystalDecisions.ReportAppServer.ReportDefModel.ISCRFieldObject<\/code><br \/>\n         <code>myFieldObject = New CrystalDecisions.ReportAppServer.ReportDefModel.FieldObjectClass()<\/code><br \/>\n         <code>myFieldObject.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindField<\/code><br \/>\n         <code>myFieldObject.FieldValueType = myField.Type<\/code><br \/>\n         <code>myFieldObject.DataSource = myField.FormulaForm<\/code><br \/>\n         <code>myFieldObject.Left = Left<\/code><br \/>\n         <code>myFieldObject.Top = Top<\/code><br \/>\n         <code>myFieldObject.Width = Width<\/code><br \/>\n         <code>myFieldObject.Height = Height<\/code><br \/>\n         <code>myFieldObject.FontColor = FontColor<\/code><br \/>\n         <code>'Add the report object to the correct section<\/code><br \/>\n         <code>rcd.ReportDefController.ReportObjectController.Add(myFieldObject, Section, 0)<\/code><br \/>\n         <code>End Sub<\/code><br \/>\n         <b>[C#]<\/b><br \/>\n         <code>public static void AddDatabaseField(string TableName, string FieldName, int Top, int Left, int Height, int Width, CrystalDecisions.ReportAppServer.ReportDefModel.Section Section,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ReportDefModel.FontColor FontColor,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rcd)<\/code><br \/>\n         <code>{<\/code><br \/>\n         <code>\/\/Find the data source field to place to add to the report<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.Field myField;<\/code><br \/>\n         <code>myField = GetField(TableName, FieldName, rcd);<\/code><br \/>\n         <code>\/\/Create the report object that will be added to the report<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject myFieldObject;<\/code><br \/>\n         <code>myFieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObjectClass();<\/code><br \/>\n         <code>myFieldObject.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindField;<\/code><br \/>\n         <code>myFieldObject.FieldValueType = myField.Type;<\/code><br \/>\n         <code>myFieldObject.DataSource = myField.FormulaForm;<\/code><br \/>\n         <code>myFieldObject.Left = Left;<\/code><br \/>\n         <code>myFieldObject.Top = Top;<\/code><br \/>\n         <code>myFieldObject.Width = Width;<\/code><br \/>\n         <code>myFieldObject.Height = Height;<\/code><br \/>\n         <code>myFieldObject.FontColor = FontColor;<\/code><br \/>\n         <code>\/\/Add the report object to the correct section<\/code><br \/>\n         <code>rcd.ReportDefController.ReportObjectController.Add(myFieldObject, Section, 0);<\/code><br \/>\n         <code>}<\/code><\/p>\n<p>To keep this code as understandable as possible, I left out many of the advanced formatting properties available. For example, you can set the properties EnableCanGrow, EnableSuppress, EnableKeepTogether, etc. These properties are found in the ISCRFieldObject.Format class. If you want to set these properties as well, in the previous listing you can add code similar to the following:<\/p>\n<p>         <code>myFieldObject.Format.EnableCanGrow = True<\/code><br \/>\n         <code>myFieldObject.Format.HyperlinkText = \"http:\/\/www.CrystalReportsBook.com\"<\/code><br \/>\n         <code>myFieldObject.Format.EnableSuppress = False<\/code><\/p>\n<p>As you can see, the RAS SDK exposes many properties that let you customize the formatting of a report object. To see a complete list of properties, please consult the help file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Add Database Field to the Report The code to add the database field to the report creates a new field object and uses the objects created in the previous code listings to set its properties. To try and keep the method as simple as possible, the FontClass object and Section object must be created prior [&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-928","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\/928","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=928"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/928\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=928"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}