Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with VFPOLEDB driver
Message
De
28/06/2007 10:50:33
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
01236245
Message ID:
01236350
Vues:
11
>Hi Cetin, apparently the "Feature is not available" anyway so I'll have to have a rethink, the site I'm on still uses Office 97 so don't know if writing directly to Excel is doable ( feel free to show me how :-) ) thanks again

Pete,
I said use 2 connection objects but later stopped on my tracks, where would the excel one come from. Maybe a predefined template. Then I tried another way and it worked:) It's somewhat of port of VFP code (my preferred copying to Excel). I used Excel COM and ADODB for it. There should be easier and COM free ways (maybe within VSTO). I don't know, for the moment this one works (skipped, saveas and close part, showing it in Excel):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using ADODB;

namespace VFP2Excel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application xl =
                new Microsoft.Office.Interop.Excel.Application();
            _Workbook wb = 
                (_Workbook)xl.Workbooks.Add(System.Type.Missing);

            xl.Visible = true;
            ADODB.ConnectionClass cn = new ConnectionClass();
            string connectionString =
                "Provider=VFPOLEDB;Data Source="+
                @"C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 9\SAMPLES\data\testdata.dbc";

            ADODB.RecordsetClass rs = new RecordsetClass();
            cn.Open(connectionString, "", "", 0);
            rs.Open("select * from customer where country like 'U%'",
                cn, 
                CursorTypeEnum.adOpenUnspecified,
                LockTypeEnum.adLockUnspecified, 0);

            Range rng = ((_Worksheet)wb.ActiveSheet).get_Range("A1", "A1");

            for (int i = 0; i < rs.Fields.Count; i++)
            {
                rng.get_Offset(0, i).Value2 = rs.Fields[i].Name;
                rng.get_Offset(0, i).Font.Bold = true;
            }

            rng.get_Offset(1, 0).CopyFromRecordset(rs, 
                System.Type.Missing, 
                System.Type.Missing);
            rs.Close();
            cn.Close();
        }
    }
}
From COM tab add Excel and ADO references.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform