{"id":925,"date":"2008-07-08T00:36:22","date_gmt":"2008-07-08T07:36:22","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/books\/?p=925"},"modified":"2010-11-17T19:17:18","modified_gmt":"2010-11-18T02:17:18","slug":"20-7-selecting-a-field","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/20-7-selecting-a-field\/","title":{"rendered":"20.07 Selecting a Field"},"content":{"rendered":"<h2>Selecting a Field from a Data Source<\/h2>\n<p>The report&#8217;s data source points to all the tables and fields that can be printed. Even if a field isn&#8217;t displayed on the report, it will still be in the data source if the report&#8217;s query specifies it to be available. The RAS object model has methods within the ReportClientDocument.Database class that make it easy to find the table and field you need. As you can see in the comments within the code listing, you first get a reference to the table using the FindAlias() method and pass it the table name. It returns the index of the table in the Tables collection. The next step calls the Table.DataFields.Find() method and passes it the field name. This returns the index of the field in the DataFields collection. A reference to this field is returned to the calling method.<\/p>\n<p>         <b>Listing 20-5. Get a reference to a field in the data source.<\/b><br \/>\n         <b>[VB.NET]<\/b><br \/>\n         <code>Public Shared Function GetField(ByVal TableName As String, ByVal FieldName As String, ByVal rcd As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument) As CrystalDecisions.ReportAppServer.DataDefModel.Field<\/code><br \/>\n         <code>Dim FieldIndex As Integer<\/code><br \/>\n         <code>Dim TableIndex As Integer<\/code><br \/>\n         <code>'Find the table's location in the table collection<\/code><br \/>\n         <code>Dim myTable As CrystalDecisions.ReportAppServer.DataDefModel.Table<\/code><br \/>\n         <code>Dim myField As CrystalDecisions.ReportAppServer.DataDefModel.Field<\/code><br \/>\n         <code>TableIndex = rcd.Database.Tables.FindByAlias(TableName)<\/code><br \/>\n         <code>Dim temp As CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable<\/code><br \/>\n         <code>temp = rcd.Database.Tables(TableIndex)<\/code><br \/>\n         <code>'Get a reference to the table object<\/code><br \/>\n         <code>myTable = DirectCast(temp, CrystalDecisions.ReportAppServer.DataDefModel.Table)<\/code><br \/>\n         <code>'Find the field's location in the field collection<\/code><br \/>\n         <code>FieldIndex = myTable.DataFields.Find(FieldName, CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault)<\/code><br \/>\n         <code>'Get a reference to the field object<\/code><br \/>\n         <code>myField = DirectCast(myTable.DataFields(FieldIndex), CrystalDecisions.ReportAppServer.DataDefModel.Field)<\/code><br \/>\n         <code>Return myField<\/code><br \/>\n         <code>End Function<\/code><br \/>\n         <b>[C#]<\/b><br \/>\n         <code>public static CrystalDecisions.ReportAppServer.DataDefModel.Field GetField(string TableName, string FieldName,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rcd)<\/code><br \/>\n         <code>{<\/code><br \/>\n         <code>int FieldIndex, TableIndex;<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.Table myTable;<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.Field myField;<\/code><br \/>\n         <code>\/\/Find the table's location in the table collection<\/code><br \/>\n         <code>TableIndex = rcd.Database.Tables.FindByAlias(TableName);<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable temp;<\/code><br \/>\n         <code>temp = rcd.Database.Tables[TableIndex];<\/code><br \/>\n         <code>\/\/Get a reference to the table object<\/code><br \/>\n         <code>myTable = (CrystalDecisions.ReportAppServer.DataDefModel.Table)temp;<\/code><br \/>\n         <code>\/\/Find the field's location in the field collection<\/code><br \/>\n         <code>FieldIndex = myTable.DataFields.Find(FieldName,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);<\/code><br \/>\n         <code>\/\/Get a reference to the field object<\/code><br \/>\n         <code>myField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)myTable.DataFields[FieldIndex];<\/code><br \/>\n         <code>return myField;<\/code><br \/>\n         <code>}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selecting a Field from a Data Source The report&#8217;s data source points to all the tables and fields that can be printed. Even if a field isn&#8217;t displayed on the report, it will still be in the data source if the report&#8217;s query specifies it to be available. The RAS object model has methods within [&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-925","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\/925","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=925"}],"version-history":[{"count":1,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/925\/revisions"}],"predecessor-version":[{"id":1830,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/925\/revisions\/1830"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=925"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}