0% found this document useful (0 votes)
5 views

Lab Database Connection Csharp 4labs

The document outlines a series of labs focused on connecting to a SQL Server database using C# and ADO.NET. It includes steps for creating a database with tables, establishing foreign keys, entering data, and querying data using various forms and controls. Additionally, it covers data binding techniques and building a three-layer architecture application in C#.

Uploaded by

thanh23122k4
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab Database Connection Csharp 4labs

The document outlines a series of labs focused on connecting to a SQL Server database using C# and ADO.NET. It includes steps for creating a database with tables, establishing foreign keys, entering data, and querying data using various forms and controls. Additionally, it covers data binding techniques and building a three-layer architecture application in C#.

Uploaded by

thanh23122k4
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

SQL Server Database Connection in C# Using ADO.

NET
LAB 1
I. Create Database
1. Create Database STUDENT_MANAGEMENT that contains table CLASS and
STUDENT
- Table CLASS

- Table STUDENT

2. Create a foreign key for column ClassID in table Student.

3. Enter data for the tables.


- Table CLASS

- Table STUDENT

1
2
II. Connect to SQL Server Database
Design Form

C# code

III.
Query Data

3
Design Form
C# code

Design Form

4
C# Code

Design Form
ListBoxC# Code

6
7
Design Form
ListView

C# Code

8
9
10
11
LAB 2: Using SqlDataAdapter
Design Form
DataGridView
C# Code

12
13
14
15

Lab 3: Windows Forms Data Binding


I. Data Binding with wizard (only using for Windows Forms App(.NET Framework))
1. Create Data Source: using Data Source Configuration
Wizard - Menu Project | Add New Data Source… or open
window Data Source (Shift+Alt+D), click Add New Data
Source…
- On the Choose a Data Source page, select Database.
- On the Choose a Database Model page, select Dataset
- On the Choose Your Data Connection page, select a data
connection from the list of available connections. If your
desired data connection is not available select New
Connection to create a new data connection.

16
- On the Save the Connection String to the Application
Configuration File page, click Next.
- On the Choose Your Database Objects page, click Next.
1
7

- Click Finish
- Click page Data Sources, the window looks like this:
2. Create form Student

18

- Choose DataGridView for the STUDENT table, drag and drop the STUDENT
table to the form.
- Choose Details for the STUDENT table, drag and drop the STUDENT table to
the form.
II. Data Binding with Controls in C#
Create a form to Show list of students by class
19

1. How to: Bind a Windows Forms ComboBox Control to Data - Create Data
Source: using Data Source Configuration Wizard - Select the cboClassID
ComboBox and follow the instructions below:
- Do the same with the cboClassName ComboBox
- Write code for the VIEW button

20

- III.

Search Form
21
LAB 4: HOW TO BUILD AND DEPLOY A THREE-LAYER
ARCHITECTURE APPLICATION WITH C#
1. Create the following form in a three-layer architecture application
-

When the user clicks the “View Student Table” button, the “Student” Table will be
displayed on the ListView.
- The solution of the application should be following:

22
2. Create the following form in a three-layer architecture application

23

You might also like