Professional Documents
Culture Documents
Visual Programming
Lab 11
Objectives
C# provides connectivity options to a large number of databases. We will be using Microsoft SQL
Server database for learning.
Connection is the basis and first step of working with a database. A connection has multiple
parameters that are database name, credentials and some options (like connection time etc.).
CRUD operations can be performed on a database. The required namespaces for these
operations are mentioned below. These should be added to your project in order to perform
database operations.
using System.Data;
using System.Data.SqlClient;
SQLDataReader: It is used for reading data only and it works on reading data as a stream. Useful
where we have to read specific data and show it on specific controls.
Task 1: UI Design
Load the project previously created having the following user interface.
using System.Data;
using System.Data.SqlClient;
Use the following function to connect to DB (as specified in connection string) whenever
needed.
Call this function in your Form Load even and display a successful message if connection is
established.
Add the following two fields in your Form UI. These fields will get data from database through
SqlDataReader.
Query to be executed:
Call the function in your Form Load class to populate our Data Table.
Additional Task:
Add searching feature in your program that searches based on specific criteria.
Pro Tips:
DataGridView provides some default operations as adding, deleting and editing. Exploit
them wherever required in order to make your application more effective.