import the data in xls file and open them without Microsoft Excel

Posted by user3669577 on Stack Overflow See other posts from Stack Overflow or by user3669577
Published on 2014-06-13T15:21:35Z Indexed on 2014/06/13 15:24 UTC
Read the original article Hit count: 285

Filed under:
|

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:

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?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about visual-studio-2010