Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to perform an application that cath values from SQL database after the esecution of a query. I must import the data in xls file and open them without Microsoft Excel. I'm a beginner and have too many problem. Can anyone help me.
This is my code, at the moment:

VB
Option Infer On
Imports System.Linq

Imports System.Data.SqlClient
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Windows.Forms
Imports ExcelLibrary.SpreadSheet





Public Class frmLottiCaricati
    Dim CnSql As SqlConnection

    Private Sub frmLottiCaricati_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.MdiParent = Inizio
        'TB_MinusValenza.Text = VariazionePrezzi.MinusValenza
        'TB_Periodo.Text = VariazionePrezzi.Periodo
        'DG_Prodotti.AutoGenerateColumns = False

        Try
            Dim StringaSql = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" + Inizio.DatabaseSql + ";Data Source=" + Inizio.ServerSql + ";User ID=" + Inizio.UtenteSql + ";Password=" + Inizio.PwdSql
            CnSql = New SqlConnection(StringaSql)
            CnSql.Open()
            Dim command As SqlCommand
            Dim dadapter As New SqlDataAdapter
            Dim DS_Prodotti As New Data.DataSet


            Dim qry_Prodotti = "SELECT sistemaf.prodscadenze.Ministeriale,  sistemaf.prodscadenze.Lotto, sistemaf.prodscadenze.Scadenza " & _
                                "FROM sistemaf.Prodscadenze "
            'INNER JOIN sistemaf.Prodscadenze  ON sistemaf.prodbase.Cod39 = sistemaf.prodscadenze.Ministeriale ;"

            command = New SqlCommand(qry_Prodotti, CnSql)
            dadapter.SelectCommand = command
            dadapter.Fill(DS_Prodotti)


            DG_Prodotti.DataSource = DS_Prodotti.Tables(0)
            'DG_Prodotti.Columns("Descrizione").Width = 220
            'DG_Prodotti.Columns("Ministeriale").Width = 60
            DG_Prodotti.Columns("Lotto").Width = 60
            'DG_Prodotti.Columns("Descrizione").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            'DG_Prodotti.Columns("Totale").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class


I can open the data only with Microsoft Excel now. Have any suggestions?
Posted
Updated 13-Jun-14 5:19am
v2

Try using this library : http://epplus.codeplex.com/[^]
 
Share this answer
 
I use ADO.net and the ACE engine.

http://www.connectionstrings.com/excel/[^]
 
Share this answer
 
try using NPOI[^] which support xls fils.
Note that EPPlus[^] supports only Open Office Xml format (xlsx)
if you going to use EPPlus then you need to find converter to convert xls files to xlsx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900