Visual Basic
Visual Basic
Lab 01:
Creating, saving and running a simple visual basic project.
Creating a new Project: Visual basic 2008
Click File Manu Click New project Or Ctrl + N
That gives a name of your Project & Ok
Now you see a new project in your Windrow.
Text box Enables you to, in a rectangular box, view, type, or edit text
or data that is bound to a cell. A text box can also be a static
text field that presents read-only information.
Command Runs a macro that performs an action when a user clicks it. A
button command button is also referred to as a push button.
In this example, the Mid function performs a direct operation on aString and assigns the value
to bString. You can also manipulate strings with the methods of the String class. There are two types of
methods in String: shared methods and instance methods.
A shared method is a method that stems from the String class itself and does not require an instance of
that class to work. These methods can be qualified with the name of the class (String) rather than with
an instance of the String class. For example:
In the preceding example, the String.Copy method is a static method, which acts upon an expression it
is given and assigns the resulting value to bString.
Instance methods, by contrast, stem from a particular instance of String and must be qualified with the
instance name. For example:
In this example, the SubString method is a method of the instance of String (that is, aString). It
performs an operation on aStringand assigns that value to bString.
All Crystal Reports programming samples in this tutorials is based on the following database
(crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to
see Database Structure .
Open Visual Studio .NET and select a new Visual Basic .NET Project.
Create a new Crystal Reports for Product table from the above database crystalDB. The Product Table
has three fields (Product_id,Product_name,Product_price) and we are showing the whole table data in
the Crystal Reports. From main menu in Visual Studio select PROJECT-->Add New Item. Then Add
New Item dialogue will appear and select Crystal Reports from the dialogue box.
Select Report type from Crystal Reports gallery.
Accept the default settings and click OK.
Next step is to select the appropriate connection to your database.
Here we are going to select OLEDB connection for SQL Server
Select OLE DB (ADO) from Create New Connection.
Next screen is the SQL Server authentication screen .
Select your Sql Server name , enter userid , password and
select your Database Name . Click next , Then the screen shows
OLE DB Property values , leave it as it is , and click finish.
Then you will get your Server name under OLEDB Connection
from there select database name (Crystaldb) and click the tables , then you can see all your
tables from your database. From the tables list select Product table to the right side list .
Click Next Button
Select all fields from Product table to the right side list.
Click Finish Button. Then you can see the Crystal Reports designer window. You can arrange the
design according your requirements. Your screen looks like the following picture.
Now the designing part is over and the next step is to call the created Crystal Reports in VB.NET
through Crystal Reports Viewer control.
Select the default form (Form1.vb) you created in VB.NET and drag a button
and CrystalReportViewer control to your form.
Select Form's source code view and put the code on top
Imports CrystalDecisions.CrystalReports.Engine
Put the following source code in the button click event
The Crystal Reports is in your project location, there you can see CrystalReport1.rpt. So give the full
path name of report here.
After you run the source code you will get the report like this.