Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

Option Strict On

$
0
0
<div title="0 Points" class="post-rating None"></div>

0 Points

27 Posts

<div class="comment-right-col">

Re: Object variable or With block variable not set

a few seconds ago|bonhommesanon|LINK

<div>

I am receiving the message just on that line of code "  Dim dr As DataRow = dsLangues.Tables(0).Rows.Add()"

 

I set the option strict on under "Tools"

But it did not work I do not see any variable without "TYPE".

 

Here is the code: TAKE A LOOK PLEASE MY FRIENDS.

 

Imports System.Data
Imports System.Linq
Imports System.Configuration
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine

Public Class Report_Test
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        If Not Me.IsPostBack Then
            Me.BindReport()
        End If
    End Sub

    Private Sub BindReport()
        Dim query As String = "SELECT TOP 5 "
        Dim isSelected As Boolean = chkColumns.Items.Cast(Of ListItem)().Count(Function(i) i.Selected = True) > 0
        If Not isSelected Then
            chkColumns.Items(0).Selected = True
        End If
        For Each item As ListItem In chkColumns.Items
            If item.Selected Then
                query += item.Value + ","
                isSelected = True
            End If
        Next
        query = query.Substring(0, query.Length - 1)
        query += " FROM Langues"
        Dim crystalReport As New ReportDocument()
        CrystalReportViewer1.DisplayGroupTree = False
        crystalReport.Load(Server.MapPath("~/CrystalReport2.rpt"))
        Dim dsLangues As Langues = GetData(query, crystalReport)
        crystalReport.SetDataSource(dsLangues)
        CrystalReportViewer1.ReportSource = crystalReport
    End Sub

    Private Function GetData(query As String, crystalReport As ReportDocument) As Langues
      

        Dim conString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim cmd As New SqlCommand(query)
        Using con As New SqlConnection(conString)

            Dim dsLangues As New Langues()

            cmd.Connection = con
            con.Open()
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                'Get the List of all TextObjects in Section2.
                Dim textObjects As List(Of TextObject) = crystalReport.ReportDefinition.Sections("Section2").ReportObjects.OfType(Of TextObject)().ToList()
                For i As Integer = 0 To textObjects.Count - 1
                    'Set the name of Column in TextObject.
                    textObjects(i).Text = String.Empty
                    If sdr.FieldCount > i Then
                        textObjects(i).Text = sdr.GetName(i)
                    End If
                Next
                'Load all the data rows in the Dataset.


                While sdr.Read()

                    Dim dr As DataRow = dsLangues.Tables(0).Rows.Add()
                    For i As Integer = 0 To sdr.FieldCount - 1
                        dr(i) = sdr(i)
                    Next
                End While
            End Using
            con.Close()
            Return dsLangues
        End Using
    End Function

    Protected Sub Columns_Changed(sender As Object, e As EventArgs)
        Me.BindReport()
    End Sub

Her I have the class for "Langues"

 Class Langues

    Public Property tag() As String
        Get
            Return m_tag
        End Get
        Set(value As String)
            m_tag = value
        End Set
    End Property
    Private m_tag As String
    'This all are the properties.
    Public Property Full_name() As String
        Get
            Return m_Full_name
        End Get
        Set(value As String)
            m_Full_name = value
        End Set
    End Property
    Private m_Full_name As String

    Public Property Language() As String
        Get
            Return m_Language
        End Get
        Set(value As String)
            m_Language = value
        End Set
    End Property
    Private m_Language As String

    Public Property Fluency() As String
        Get
            Return m_Fluency
        End Get
        Set(value As String)
            m_Fluency = value
        End Set
    End Property
    Private m_Fluency As String

    Public Property Competency() As String
        Get
            Return m_Competency
        End Get
        Set(value As String)
            m_Competency = value
        End Set
    End Property
    Private m_Competency As String

    Public Property Description() As String
        Get
            Return m_Description
        End Get
        Set(value As String)
            m_Description = value
        End Set
    End Property
    Private m_Description As String

    Property Tables(p1 As Integer) As Object
        Get
            Return _tables
        End Get
        Set(value As Object)
            _tables = value
        End Set
    End Property
    Private _tables As Object
End Class

</div> </div>

Viewing all articles
Browse latest Browse all 1507

Trending Articles