Download presentation
Presentation is loading. Please wait.
1
Creating SQL Database file And Displaying a Database Table in a DataGridView
2
Basic Database Concepts
A database: is a collection of related data, organized into entities called tables that are connected together by relationships. A Table: is a part of the database that contains related information about a certain entity (Students, Teachers, Faculties, etc.). A table consists of fields that represent the needed information. A certain data type should be specified for each field (e.g. StudentName "string or varchar", CreditHours "Int", etc.) Primary Key: A unique field, that shouldn't be repeated in any record, and shouldn't be null.
3
Basic Database Concepts
4
Create new windows application project
5
Click on add new data source option in data source window
6
In choose data source type dialog box select Dataset then click next
7
In choose your data connection dialog box click on new connection button
8
Select Microsoft SQL Server Database file option as a data source then click on continue button
9
In Add connection dialog box enter a name for the database file ex: database1 then click on ok button
11
A massage box will appear to tell you that this is a new database would you like to create it? Click on yes button
12
Now a new database is created with a specific connection string that will be used to connect the application to this database.
13
Click next
14
Click on NO button
15
Click on next
16
Click on previous button
17
Click on finish button
19
Open server explorer then click on database1
Open server explorer then click on database1.mdf then right click on Tables and choose Add new Table option
21
Add new filed "name" to the table as following
22
To save changes on the table click on update then Click on update database button
24
To change table name to "student"
25
Update the database then close the table
26
On data source window right click on database1Dataset then choose Configure data source with wizard then choose tables
27
Then choose table click finish
29
Drag and drop student table from data source window to the form
30
Run the program
31
Add new record then click save
32
Remove the record then click save
33
How Data Binding Works The technique through which GUI controls are connected to data sources is known as data binding. The IDE allows controls, such as a DataGridView, to be bound to a data source, such as a DataSet that represents a table in a database. Any changes you make through the application to the underlying data source will automatically be reflected in the way the data is presented in the data-bound control (e.g., the DataGridView). Likewise, modifying the data in the data-bound control and saving the changes updates the underlying data source.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.