Académique Documents
Professionnel Documents
Culture Documents
Option Explicit On Option Strict On Imports System.Data.SqlClient Public Class CrearXml Private msTabla As String Private msQuery As String Private msCadConexion As String Public Sub New(ByVal vsTabla As String, ByVal vsQuery As String, ByVal vsCadConexion As String) msTabla = vsTabla msQuery = vsQuery msCadConexion = vsCadConexion End Sub Public Function gF_CrearDataTableSql() As DataTable Dim loDataSet As New DataSet Dim loDataTable As DataTable = Nothing Try Using loConexion As New SqlConnection(msCadConexion) Dim loDataAdapter As New SqlDataAdapter(msQuery, loConexion) loDataAdapter.Fill(loDataSet, msTabla) loDataTable = loDataSet.Tables(msTabla) End Using Catch Exp As Exception MessageBox.Show(Exp.Message, "gF_CrearDataTableSql", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try Return loDataTable End Function Public Sub gP_CrearFicheroXML(ByVal FilePath As String) Dim loDataTable As DataTable= gF_CrearDataTableSql() loDataTable.WriteXmlSchema(FilePath) End Sub End Class
Se pulsa siguiente.
Se pulsa siguiente.
Se pulsa Finalizar, y ya tenemos el fichero Vincula.rpt creado. Manipulando un poco el fichero rpt, lo he dejado asi:
Si se cambia de origen de datos por ejemplo un MDB no importa, el nico requisito es que en el datatable que se le cargue al fichero rpt, contenga todos los campos que contiene el informe.
If ldtDataTable Is Nothing Then MessageBox.Show("No hay datos", "FrmXXX_Load", MessageBoxButtons.OK, MessageBoxIcon.Information) Me.Close() End If Me.rdInforme.SetDataSource(ldtDataTable) Me.crvInforme.ReportSource = Me.rdInforme End Sub Private Function lF_dtCrearDataTable() As DataTable Dim loDataTable As New DataTable Try Using loConexion As New SqlConnection(msCadConexion) Dim loDataAdapter As SqlDataAdapter loDataAdapter = New SqlDataAdapter(msConsulta, loConexion) loDataAdapter.Fill(loDataTable) End Using Catch Exp As SqlException MessageBox.Show(Exp.Message, "lF_dtCrearDataTable", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try Return loDataTable End Function End Class