Database Creation

Download Report

Transcript Database Creation

Creating SQL Database file And
Displaying a Database Table in a
DataGridView
Create new windows application project
Click on add new data source option in data source
window
In choose data source type dialog box select Dataset
then click next
In choose your data connection dialog box click on
new connection button
Select Microsoft SQL Server Database file option as a
data source then click on continue button
In Add connection dialog box enter a name for the
database file ex: database1 then click on ok button
A massage box will appear to tell you that this is a
new database would you like to create it? Click on yes
button
Now a new database is created with a specific
connection string that will be used to connect the
application to this database.
Click next
Click on NO button
Click on next
Click on previous button
Click on finish button
Open server explorer then click on database1.mdf
then right click on Tables and choose Add new Table
option
Add new filed "name" to the table as following
To save changes on the table click on update then
Click on update database button
To change table name to "student"
Update the database then close the table
On data source window right click on
database1Dataset then choose Configure data source
with wizard then choose tables
Then choose table click finish
Drag and drop student table from data source
window to the form
Run the program
Add new record then click save
Remove the record then click save
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.