C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Visual Studio »

Creating report in vb.net through coding.


Posted Date: 01 Sep 2009    Resource Type: Code Snippets    Category: Visual Studio
Author: NeetuMember Level: Diamond    
Rating: 1 out of 5Points: 6



Description :


In this i have created one form which will ask deptno from the user. then depends on the selection. It will give you the report.


Imports System.Data.OleDb
'For sqlserver
'Imports System.Data.SqlClient
'CrystalDecisions.CrystalReports.Engine is a dll which is used for the creation of reports.
Imports CrystalDecisions.CrystalReports.Engine
Public Class Reportcode
Dim con As OleDbConnection
'dim con As SqlConnection (For sqlconnection)
'DataTable is used for the storage of data which we get from the database
Dim dt As DataTable
'Dataadapter is used to fill the data from the database into datatable
Dim da As OleDbDataAdapter
'Reportdocument is bind with the reportviewer to show the report.
Dim obj As New ReportDocument
'StringBuilder is class used to build multiple strings and create the sentence.
Dim str As New System.Text.StringBuilder
Private Sub Reportcode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

str.Append("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=")
'AppDomain.CurrentDomain.BaseDirectory will give you path of debug folder in your current solution
Str.Append(AppDomain.CurrentDomain.BaseDirectory)
str.Append("test.mdb")
Str.Append(";Persist Security Info=False")
con = New OleDbConnection
'ConnectionString is property used for the connecting with the database.
con.ConnectionString = str.ToString
'For sqlconnection
'con.ConnectionString = "workstation id=HOME;packet size=4096;integrated security=SSPI;initial catalog=IMS" & _
' ";persist security info=False"
'Distinct keywords gives you data which is not duplicated in table.
da = New OleDbDataAdapter("select distinct(deptno) from emp", con)
dt = New DataTable
da.Fill(dt)
'To bind datatable with combobox
cmbdept.DataSource = dt
'DisplayMember is used to show the data of particular column
cmbdept.DisplayMember = "Deptno"
da = Nothing
dt = Nothing
End Sub
Private Sub cmdreport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdreport.Click
Dim cmd As New OleDbCommand
Dim str1 As String
Dim str2 As String
dt = New DataTable
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select * from emp where deptno=" & Val(cmbdept.Text)
da = New OleDbDataAdapter(cmd)
da.Fill(dt)
Dim str As String
str = AppDomain.CurrentDomain.BaseDirectory
str1 = str.Remove(str.IndexOf("bin"), 10)
str2 = str1 & "RptCode.rpt"
'MsgBox(str2)
'Str1 contains the path of report.
obj.Load(str1 & "RptCode.rpt")
'Binding the table with the reportdocument object
obj.Database.Tables(0).SetDataSource(dt)
'Binding the document with the reportviewer control
CrystalReportViewer1.ReportSource() = obj
End Sub
End Class


<img src="c:\report.jpg">


Check the attachement.
regards
Neetu

Attachments

  • Creating report in vb.net through coding. (32082-11157-ReportsEx.rar)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Creating report in .net through coding  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: How to send selected data from one ListBox to another ListBox?
    Previous Resource: AutoComplete Textbox in Windows Application
    Return to Discussion Resource Index
    Post New Resource
    Category: Visual Studio


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use