Steps to Create Crystal Report in VB.NET


Thursday, March 25, 2010

In this tutorail, I will teach you how to make crystal report in vb.net.

Please follow the Steps to Create Crystal Report in VB.NET,

Step 1: Create one vb.net project in visual studio.

Step 2: what we need to create simple crystal report ?
a.Dataset file (.xsd)
b.Crystal Report (.rpt)
c.One window form (.vb)


Crystal report by Induway Technologies (www.induway.com)


Step 3: Right click on project name in visual studio and click on add to add new items.

Step 4: Select Dataset from the list from Add New Item displayed box.
Name it as ReportDS as shown in Video.
Then you will be prompt with gray screen, it shows you have created dataset properly.
Drag Table from the Server explorer and drop it on dataset gray screen.


Step 5: Now its time to insert report file (.rtp), right click on project name in visual studio and click on add to add new items.

Step 6: Select CrystalReport from the list from Add new item displayed box.
Name it as Crystalreport1 as shown in video.
Then you will be prompt with the Crystal Reports Gallery,
Just click on "OK", then another page "Standard Report creation Wizard" will be prompted.
Then you need to select the database you created, in step 4.
For that click on ADO.NET Dataset and select you dataset from the list.as shown in video.
Then you will be prompted with table with fields, select the fields you require to show in report.
Then click on finish, and you have done.

Step 7: Now you need to add from to show this report in it. To do that, just add new form (.vb), and drag the Reportviewer form the data section in tool box.

Step 8: Take one button in that from, so that, when you click on that button, the report show appear.

Step 9: Then on click event of that button, paste this code below.

Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=PAMDB.mdb;User Id=admin;Password=;")
Dim cmd As OleDbCommand
cmd = New OleDbCommand("SELECT PAM_Medical_Information.tPatientName, PAM_Medical_Information.tDoctorCareProvider, PAM_Type_of_Medical_Entry.tMedicalTypeName, PAM_Medical_Information.tRx_OTC_MedsList_Dosage_Frequency, format(PAM_Medical_Information.dMedicalDate,'MM/dd/yyyy') as dMedicalDate , iif (PAM_Medical_Information.tPutOnMedicalInformationCard = '1', 'Yes', 'No') as tPutOnMedicalInformationCard FROM PAM_Medical_Information INNER JOIN PAM_Type_of_Medical_Entry ON PAM_Medical_Information.nMedicalTypeID = PAM_Type_of_Medical_Entry.iMedicalTypeID", conn) ' Change ID

Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet() 'Set TypeDataset name That I have created before
da.Fill(ds, "MedicalList")
If (ds IsNot Nothing And ds.Tables(0).Rows.Count > 0) Then
Dim cryRpt1 As New ReportDocument
Dim reportpath As String = Application.StartupPath & "\Reports\Medical.rpt"
'cryRpt1.Load(reportpath)
cryRpt1.Load(reportpath)
cryRpt1.SetDataSource(ds.Tables(0))
CrystalReportViewer1.ReportSource = cryRpt1
CrystalReportViewer1.Refresh()
End If



Thats it, you have done finally, enjoy the report.

Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com


.

How to define Global Variable in Windows Forms with C#




Create one Static class and declare static member/property into that class.

Now you can access that variable from any form in your windows application. Also you can able to set and get variable values.

GlobalModule Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class GlobalModule
{

private static string _GlobalVar = "";
public static string GlobalVar
{
get { return _GlobalVar; }
set { _GlobalVar = value; }
}

public static string FirstName = "Rajesh";
}



How to use global variables in application:


//Set the value to static variable
GlobalModule.GlobalVar = "VB.Net C#";

//Get the value from static variable
string CheckVal = GlobalModule.GlobalVar;
string FirstName = GlobalModule.FirstName;



Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com


.

How to get @@Identity after insert operation in Access Database


Saturday, March 20, 2010

Solution :

I am going to explain this in Vb.Net.

Create one vb.net project and add one from frmAddContact.vb in your project.
and take one button and txtbox in that form.

Create Dataaccesslayer class file with name, DAL.vb

and add below code to respective files, please find the code below.


frmAddContact.vb

Dim ObjDataAccess As New DAL()
Public Class frmAddContact
Dim ObjDataAccess As New DAL()

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

Dim iRelationID As New Integer
iRelationID = ObjDataAccess.ExecuteNonQueryGetIdentity("INSERT INTO PAM_Relationship ( tRelationshipName,dCreatedDate,dModifiedDate) VALUES ('" & _
cmbrelationship.Text.Trim() & "',#" & _
Date.Now & "#,#" & _
Date.Now & "# )")

End Sub
End Class





DAL.vb

Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.OleDb

Public Class DAL
Dim ConnStr As String = Configuration.ConfigurationSettings.AppSettings("DBConn").ToString()

Public Function ExecuteNonQueryGetIdentity(ByVal Query As String) As Integer

Dim iResult As Integer
Try
Dim Conn As New OleDb.OleDbConnection(ConnStr)
Conn.Open()
Dim cmd As New OleDb.OleDbCommand(Query, Conn)

cmd.ExecuteNonQuery()
cmd.CommandText = "Select @@Identity"
iResult = cmd.ExecuteScalar()
Conn.Close()
cmd.Dispose()
Catch ex As Exception
ex = Nothing
End Try

Return iResult
End Function

End Class


After insert operation, when you will check the value of return value of iRelationID, you will find the inserted row id.


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com


.

Delete all image file from Perticular folder in C#


Friday, March 19, 2010

Hello DotNet Developer,

Please find below code, which will help to find all file in perticular folder and delete all the file and make folder blank.

Explaination of the code : Delete all image file from Perticular folder in C#

Here, i have find the folder path using Server.MapPath, then stored all the file in the array, i have named it imglist.

Then i have used forloop to get all the files name one by one and delete it,
Here i have taken DateTime.Now.AddMinutes, because if the file is added just before 3 minutes from the current time, then it should not be delete, you can change the time according to your need.

Code :

protected void CleanImageFolder()
{
string imgFolder = Server.MapPath("~/lab/maskemail/img/");
string[] imgList = Directory.GetFiles(imgFolder, "*.jpg");
foreach (string img in imgList)
{
FileInfo imgInfo = new FileInfo(img);
if (imgInfo.LastWriteTime < DateTime.Now.AddMinutes(-3))
{
imgInfo.Delete();
}
}
}



Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com