Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2019, 08:36 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 299
Default Check the datatype of the datafields of the RecordSet of TADODataset

Dear Expert,

I have been using the below code to check the datatype of the datafields of TClientdataset:

if (cdsReport.Fields[col].DataType = ftDateTime) then
//something here

Now, how shall i check the datatype of the datafields of the RecordSet of TADODataset.

THanks in advance.
__________________
Rmt
Reply With Quote
  #2  
Old 03-26-2019, 09:02 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

TAdoDataset should have a FieldDefs property
And from there, a TFIeldDef.DataType
But I'm not sure if this is when you build your own Dataset or if that is also filled when you fill your Dataset through a Query.

But I find it weird that the TAdoDataset doesn't have a Fields, are you sure about this?
What you could always try is a ADODataset.FieldByName().DataType
Reply With Quote
  #3  
Old 03-26-2019, 04:49 PM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 299
Default

Dear Norrit,

Actually I have the code below to export adoDataSet Recordset into Excel. Now, I want to format the DATE column in excel with some datemask like 'yyyy-mm-dd'. So, how shall i check if the field of Recordset is Date. Kindly suggest.

HTML Code:
procedure TformPreviewReport.ExportRecordsetToMSExcel(Data: _Recordset);
var
  ovExcelApp: OleVariant;
  ovExcelWorkbook: OleVariant;
  ovWS: OleVariant;
  ovRange,ovColRange1,ovColRange2,ovColRange3,ovColRange4: OleVariant;
 iCol,jRow : Integer;
  v   : Variant;
begin
ovExcelApp := CreateOleObject('Excel.Application'); //If Excel isnt installed will raise an exception
        ovExcelApp.Visible:=False;
  try
    ovExcelWorkbook   := ovExcelApp.WorkBooks.Add;
    ovWS := ovExcelWorkbook.Worksheets.Item[1]; // go to first worksheet
    ovWS.Activate;
    ovWS.Select;
    ovRange := ovWS.Range['A1', 'A1']; //go to first cell
     
                ovWS.Cells[1, 1] := fReportHeader;
                ovRange := ovWS.Range['A2', 'A2']; //go to first cell  of second row
                jRow := 2;  


        ovRange.Resize[Data.RecordCount+1, Data.Fields.Count];

        for iCol := 1 to Data.Fields.Count do
        begin
                v := Data.Fields[iCol-1].Name;
               ovWS.Cells[jRow, iCol] := v;
        end;

                ovRange := ovWS.Range['A3', 'A3'] //go to first cell of third row
     
    ovRange.CopyFromRecordset(Data, Data.RecordCount, Data.Fields.Count); //this copy the entire recordset to the selected range in excel
     ovWS.SaveAs(GetSharedDir+'\MBNepalReports\'+fReportName+'.xls', 1, '', '', False, False);

  finally
    ovExcelWorkbook.Close(SaveChanges := False);
    ovWS := Unassigned;
    ovExcelWorkbook := Unassigned;
    ovExcelApp := Unassigned;
    MessageDlg('Export Completed. Please check '+GetSharedDir+'\MBNepalReports\'+fReportName+'.xls',mtInformation,[mbOk],0);
        Close;
  end;

end;
thanks...
__________________
Rmt
Reply With Quote
  #4  
Old 03-27-2019, 09:22 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

You could try something like:
Code:
ovRange.Columns(1).Numberformat := 'yyyy-mm-dd'
I guess you should call this beofre the CopyFromRecordset, so the range knows what to expect...

Last edited by Norrit; 03-27-2019 at 09:22 AM. Reason: Sorry, not Delphi syntax
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:27 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.