Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi,

I wanted to ask on how to create Report (like a Crystal Report) in VB.Net with smartdevice project?

I have a dataset and a database transaction about sell and buy (like a PoS).
So I need to create report on :
- who bought my product (Name,Address and so on)
- what product they buy
- Date time
- Total Cost, price, and so on.

I need this report available to be printed via PDA with thermal printer.

Thanks a lot in advnced.
Posted

1 solution

Hi,

Just try this sample if this could help:

In this sample i created class called customer
code as follows:

Imports Microsoft.VisualBasic
Public Class customer
    Private _cust_name As String
    Private _cust_addr1 As String
    Public Property Cust_Name() As String
        Get
            Return _cust_name
        End Get
        Set(ByVal value As String)
            _cust_name = value
        End Set
    End Property
    Public Property Cust_addr1() As String
        Get
            Return _cust_addr1
        End Get
        Set(ByVal value As String)
            _cust_addr1 = value
        End Set
    End Property

    
    Public Sub New( ByVal cust_name As String,ByVal cust_addr1 As String)
        _cust_name = cust_name
        _cust_addr1 = cust_addr1
    End Sub
End Class



In your client side let say default.aspx Source,
Drag CrystalReportViewer in your Toolbox and place
between the <div> tag.

example:
<div>
  ' Drag it and place here...
</div>



In my code behid .aspx.vb
as follows:

Imports System.Data
Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Reflection
Partial Class _Default
    Inherits System.Web.UI.Page
    Public ConnStr As String = _
    ConfigurationManager.ConnectionStrings("ClaimsSQLConnection").ConnectionString.ToString()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim rptLoc As String = Server.MapPath("") + "\Reports\AspSample.rpt"
        Dim crpt As ReportDocument = New ReportDocument()
        Dim dt2 As New DataTable
        Dim ds As New DataSet1
        Dim query As String = "select * from dbo.Customer"
        Dim dt1 As List(Of customer) = GetCustomer(query, ConnStr)
        crpt.Load(rptLoc)
        crpt.SetDataSource(ds)
        ds.MyDatasetTable.Clear()
        For index As Integer = 0 To dt1.Count - 1
            Dim drt As DataRow
            drt = ds.MyDatasetTable.NewRow()
            drt("Customer Name") = dt1(index).Cust_Name
            drt("Customer Address1") = dt1(index).Cust_addr1
            ds.MyDatasetTable.Rows.Add(drt)
        Next
        CrystalReportViewer1.ReportSource = crpt
    End Sub
    Public Shared Function GetCustomer(ByVal query As String, _
        ByVal connStr As String) As List(Of customer)
        Dim lst As List(Of customer) = New List(Of customer)
        Dim sb As StringBuilder = New StringBuilder()
        Dim conn As SqlConnection = New SqlConnection(connStr)
        sb.Append("select * from dbo.customer ")
        Dim qry As String = sb.ToString()
        Try
            Dim cmd As New SqlCommand(qry, conn)
            conn.Open()
            Using (cmd)
                cmd.CommandType = CommandType.Text
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                Using (dr)
                    While (dr.Read())
                        Dim temp As New customer( _
                            Convert.ToString(dr.Item("cust_name")), _
                            Convert.ToString(dr.Item("cust_add1")))
                        lst.Add(temp)
                    End While
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        Finally
            conn.Close()
        End Try
        Return lst
    End Function
End Class



Regards,
 
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