0% found this document useful (0 votes)
19 views17 pages

OOP Module8 HFEstrada Oct22 New

Uploaded by

Alyssa Rama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views17 pages

OOP Module8 HFEstrada Oct22 New

Uploaded by

Alyssa Rama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DYBITOOP123:

OBJECT ORIENTED PROGRAMMING

HERLIZA FELIPE ESTRADA


Instructor, College of Computer Studies

Declaration:
This learning module is an exclusive property of Dr. Yanga’s Colleges, Inc., as an essential part of the
REIMAGINED Learning Program for the Academic Year 2020-2021, and shall only be used by and for
DYCIans. No part of this learning module shall be reproduced, distributed, transmitted, and/or sold, without
the consent of DYCI.
MODULE 8
SEARCH AND FILTER RECORD

This module will help you acquire knowledge on how to search single record and fil-
ter record loaded in a data grid view using VB.net and MySQL

At the end of this module, you are expected to:


1. Determine how to search single record and load in a text field
2. Determine how to filter record in a DataGridView.
3. Create an application that will search and filter record.

Retrieve Single Result in the Database:


 This method has the ability to retrieve the data in the database and display the spe-
cific field in the textboxes.
 It has a function that when you write an ID no. Or the full name or the username
of the user it will then display the student details in the textboxes.

Creating Database:

Create a database named `vbmysqldb`. Execute the following query to create a table.

CREATE TABLE `tbluseraccounts` (


`ID` int(11) NOT NULL,
`fullname` varchar(30) DEFAULT NULL,
`username` varchar(30) DEFAULT NULL,
`pass` varchar(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

2
Execute the following query to add the data in the table that you have created.
INSERT INTO `tbluseraccounts` (`ID`, `fullname`, `username`, `pass`)
VALUES (1, 'liza', 'liza', 'liza'),
(2, 'juan', 'juan', 'juan'),
(3, 'honey', 'honey', 'honey');

Creating Application
Step 1 :Open Microsoft Visual Studio and create a new windows form application in
visual basic. Change the project name and the location if necessary.

3
Step 2 : Design the form just like shown below.

 Set the items(collection) of cbooption: ID, Fullname, Username


Step 3
Open the code editor by pressing F7 on the keyboard. After that, add a namespace
above the public class to access MySQL Libraries and variables needed.
Imports MySql.Data.MySqlClient

Step 4
Create a connection between Visual Basic and MySQL Database. After that, declare all
the classes that are needed.

4
Step 5. On form load call the ConnectDatabase() function to establish connection

5
Step 6: Add functionality to your Back Button

Step7: Create Function retrieve_single_result

6
Step 8: Add a function to filter record by ID: ToString used to convert DBNull into
string vlaue

Step 9: Add a function to filter record by Fullname

7
Step 10: Add a function to filter record by Username

Step 11. Add functionality to your Search Button

8
Step 11: Add functionality to your Clear button and Keypress event to your TXTDATA

9
Search/Filter datagridview using textbox.
Step 1: Add new windows form and design as shown below:

Step2. After setting up the Form, double click it and do this code for setting up the
connection of MySQL Database to Visual Basic and declare all the classes that are
needed.

Step 3: Add database connection function to your form load

10
Step 3: Write the function to connect to your database

Step4: Format the password column of your Data Grid View

11
Step 5: Add the key press event of your TXTDATA

Step 6: Run the program

12
VB.NET DataGridView
 The DataGridView control provides a customizable table for displaying data.
 This control is designed to be a complete solution for displaying tabular data with
Windows Forms.
 Also the DataGridView class allows us to customization of cells, rows, columns, and
borders through the use of its properties
Lightning bolt.
When using the DataGridView control in Windows Forms, you should use
the lightning bolt panel. This allows you to manipulate the events on the
control. DataGridView has many events, and this article doesn't describe
them all.

DataGridView.AutoResizeColumns Method
 Adjusts the width of all columns to fit the contents of their cells.
 Adjusts the width of all columns to fit the contents of all their cells, including the
header cells.
OVERLOADS

AutoResizeColumns()

 Adjusts the width of all columns to fit the contents of all their cells, including the
header cells.
AutoResizeColumns(DataGridViewAutoSizeColumnsMode)

 Adjusts the width of all columns using the specified size mode.
AutoResizeColumns(DataGridViewAutoSizeColumnsMode, Boolean)

 Adjusts the width of all columns using the specified size mode, optionally calculating
the widths with the expectation that row heights will subsequently be adjusted.

13
DataGridView.AllowUserToResizeColumns Property
 Gets or sets a value indicating whether users can resize columns.

DataGridView.AllowUserToDeleteRows Property
 Gets or sets a value indicating whether the user is allowed to delete rows from
the DataGridView.

DataGridView.AllowUserToAddRows Property
 Gets or sets a value indicating whether the option to add rows is displayed to the user.

DataGridView.AllowUserToResizeRows Property
 Gets or sets a value indicating whether users can resize rows.

DataGridView.DefaultCellStyle Property
 Gets or sets the default cell style to be applied to the cells in the DataGridView if no
other cell style properties are set.

DataGridView.RowsDefaultCellStyle Property
 Gets or sets the default style applied to the row cells of the DataGridView.

DataGridView.AlternatingRowsDefaultCellStyle Property
 Gets or sets the default cell style applied to odd-numbered rows of the DataGridView.

DataGridView.BackColor Property
 Gets or sets the background color for the control.

14
Name: _____________________________________________ Rating: ________________
Year and Section:_____________ Professor / Instructor: __________________________
Due of Submission: _____________________________

1. Open the activity project created in module 7 as shown below:

2. Add the following object in your form1.

3. Change the name of the text box into “txtData”

4. Add a functionality to filter the data in the DataGridView when your enter ei-
ther the ID, name or username of the user.

5. Add another button to link your form1 and form2.

15
Name: _____________________________________________ Rating: ________________
Year and Section:_____________ Professor / Instructor: __________________________
Due of Submission: _____________________________

6. Add new form and design as shown below:

Set the items(collection) of cbooption: ID, Fullname, Username

7. Add functionality to the search button and txtData “Keypress Event” accord-
ing to the value of your “cbooption” and load the retrieved record in a text-
field in the group box.

8. Add functionality to the clear button and the Back button.

16
guru99.com. (2020, June 6). V B.NET Tutorial: Learn V B.Net programming. Retrieved
from https://www.guru99.com/vb-net-tutorial.html.
hscripts.com. (2020). V B.Net Tutorial - Microsoft Visual Basic Programming. Re-
trieved from https://www.hscripts.com/tutorials/vbnet/index.php.
Pepito, C. P. (2011). Itnroduction to V isual Basic 2008 Programming. Philippines: Na-
tional Book Store.
Tamayo, J. D., Taguinod, I. C., Gibaga, G. R., Malang, B. P., Macatangga, R. S., &
Casuco Jr., F. S. (2014). V B.Net Programming. Malabon City: Jimczyville Pub-
lications.
techotopia.com. (2020). V isual Basic Essentials. Retrieved from techotopia.com/
index.php/Visual_Basic_Essentials
tutorialspoint.com. (2020, June 6). V B.Net Programming Tutorial. Retrieved from
https://www.tutorialspoint.com/vb.net/index.htm.
vb.net-informations.com. (2020, June 6). V B.NET Tutorial. Retrieved from http://
vb.net-informations.com/.
vbtutor.net. (2020, June 6). V isual Basic 2008 Tutorial. Retrieved from https://
www.vbtutor.net/vb2008/vb2008tutor.html.

17

You might also like